Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:26:32+00:00 2026-06-01T22:26:32+00:00

In one of my projects I’m trying to redirect using .htaccess. I am using

  • 0

In one of my projects I’m trying to redirect using .htaccess. I am using a redirect like this:

RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

But, now I’d like to add an exception to the rewrite rules. I want http://example.com/admin/ to be redirected in the same way, only to a different directory. All of the other traffic should still go to the public directory. So i added a rewrite condition like this:

RewriteCond %{REQUEST_URI} !/admin/
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

This didn’t do the trick. I am still being redirected to the public folder. I also tried this:

RewriteRule ^admin$ admin/ [L]
RewriteRule admin(.*) admin/$1 [L]

RewriteCond %{REQUEST_URI} !/admin
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

This only made things worse. I now get an 500 internal server error.

I have been searching for hours now, and I’m getting a bit tired of finding examples that show how to add an exception for a certain folder, but don’t show how to redirect this traffic to another folder. Can you tell me what I’m doing wrong, or which other approach I could try?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:26:35+00:00Added an answer on June 1, 2026 at 10:26 pm

    A RewriteCond only applies to the rule directly beneath it. In other words, in your example, it’s only applied to the empty path rule. Move the RewriteCond down one notch, and it will work better.

    RewriteRule ^$ public/ [L]
    
    RewriteCond %{REQUEST_URI} !/admin/
    RewriteRule (.*) public/$1 [L]
    

    Additionally, I find your rule

    RewriteRule admin(.*) admin/$1 [L]
    

    to be odd. A URL like /adminsomething will be rewritten to /admin/something which I don’t think is what you want.

    Furthermore I have a hunch that you’re confusing a rewrite with a redirect. A rewrite is a rule that makes a request be rewritten internally and interpreted differently. A redirect is a rule that will tell the visitor’s browser to go to a different address. Which one are you going for?

    The magic keyword for a redirect is R=301 which means redirect with http code 301 Moved Permanently. For example, you may want to try…

    # This first rule is actually redundant in this case so skip it...
    #RewriteRule ^$ public/ [R=301,L]
    RewriteCond %{REQUEST_URI} !/admin
    RewriteRule (.*) public/$1 [R=301,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MbUnit one can do something like this: [Test] [TestCategory(Bad Arguments)] [TestCategory(Fast)] [ExpectedException(typeof(ArgumentNullException))] public
I am using FullCalendar in one my projects and would like to plot recurring
After numerous projects one-way asynchronous message passing looks like the only way to write
In one of my projects, I'm using an n-tier architecture DAL (Repository Pattern) <->
For one of my projects, I'm using the DOMDocument class to load and manipulate
Here's my problem: I have 2 projects - one 'common' projects with acts like
I've got a feature enablement mechanism in a couple of projects (one using RSpec
I have two projects.One project is build in MVC asp.net and the other project
I have a solution with 3 projects.One of UI (contains web pages) and one
I have the digdog MapKitDragAndDrop in one my projects to achieve drag and drop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.