Jump to content

.htaccess re-direct help


MoFish

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
https://forums.phpfreaks.com/topic/287806-htaccess-re-direct-help/
Share on other sites

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".

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.