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
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]

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.