Jump to content

Redirect traffic except two files


Recommended Posts

I'm trying to redirect all traffic to a domain to another domain except two files.

 

I tried the following and the files are forwarding:

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain.com [NC]
RewriteRule ^(.*) http://domain.com/$1 [L,R=301]

RewriteBase /
RewriteCond %{REQUEST_URI} !^exception1\.php$
RewriteCond %{REQUEST_URI} !^exception2\.php$
RewriteRule ^.+$ http://otherdomain.com [L,R=301]

 

EDIT: Sorry. For two files. I have no idea why I said one.

 

I don't really know much about mod_rewrite so any help is much appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/
Share on other sites

Try...

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain.com [NC]
RewriteRule ^(.*) http://domain.com/$1 [L,R=301]

RewriteBase /
RewriteCond %{REQUEST_URI} !^/exception1\.php$
RewriteCond %{REQUEST_URI} !^/exception2\.php$
RewriteRule ^.+$ http://otherdomain.com [L,R=301]

 

Hm.. what happens without the first redirect, I tested that second part locally and it seems to work fine. Try redirecting to a page on your server that echo's out $_SERVER['REQUEST_URI'], that way you should get an idea why it's not matching.

Still forwards.

 

Here's my entire htaccess file after the changes:

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes

RewriteBase /
RewriteCond %{REQUEST_URI} !^/contact\.php$
RewriteRule ^.+$ http://charlieholder.com [L,R=301]

It's working as expected now.

 

I don't see why it took time. I cleared my cache and cookies and now it's working as expected. I don't know if that's something that would make it work, I would think it checks the server every time, but I don't know.

 

Thanks.

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.