Jump to content

.htaccess re-direct help


MoFish
Go to solution Solved by requinix,

Recommended Posts

Hi,

 

I'm not sure if this is in the correct forum - hope so!

 

I've been trying to re-direct all my website traffic to another website url (bbc.co.uk) apart from one particular folder (/install) which should be accessible.

 

Can anyone help me with this? I think i'm close...

RewriteEngine on
RewriteRule !^install($|/) http://www.bbc.co.uk%{REQUEST_URI} [L,R=301]

Thanks,

 

MoFish

Link to comment
Share on other sites

  • Solution

I'm not sure if this is in the correct forum - hope so!

We have a forum specifically for mod_rewrite and URL rewriting questions, so while Regex is close, this place is actually better. No worries though.

 

There's three ways you can go about this and they all look and work about the same:

1. Do one RewriteRule for the folder you want to ignore and make it do nothing - except stop the rewriting. Then the second RewriteRule can just redirect everything it sees.

RewriteEngine on
RewriteRule ^install(/|$) - [L]
RewriteRule ^ http://www.bbc.co.uk%{REQUEST_URI} [L,R=301]
2. Use a RewriteCond to make sure the RewriteRule only applies to the folders you want it to.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^(?!install(/|$))
RewriteRule ^ http://www.bbc.co.uk%{REQUEST_URI} [L,R=301]
3. Make your one RewriteRule exclude that folder, which is what you're aiming for.

RewriteEngine on
RewriteRule ^(?!install(/|$)) http://www.bbc.co.uk%{REQUEST_URI} [L,R=301]
If you're wondering, the (?!...) construct translates to "... does not match here".
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.