soycharliente Posted March 6, 2010 Share Posted March 6, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/ Share on other sites More sharing options...
cags Posted March 6, 2010 Share Posted March 6, 2010 What URL are you testing it with? What's the outcome? Are all files being forwarded including the ones you wish to be exceptions? Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022177 Share on other sites More sharing options...
soycharliente Posted March 6, 2010 Author Share Posted March 6, 2010 I'm testing with: www.domain.tld domain.tld domain.tld/exception1.php domain.tld/exception2.php www.domain.tld/exception1.php www.domain.tld/exception2.php Everything redirects to otherdomain.tld Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022179 Share on other sites More sharing options...
cags Posted March 6, 2010 Share Posted March 6, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022180 Share on other sites More sharing options...
soycharliente Posted March 6, 2010 Author Share Posted March 6, 2010 Adding the slash before the file yields the same result. Still forwards on. Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022182 Share on other sites More sharing options...
cags Posted March 6, 2010 Share Posted March 6, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022193 Share on other sites More sharing options...
soycharliente Posted March 7, 2010 Author Share Posted March 7, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022718 Share on other sites More sharing options...
soycharliente Posted March 7, 2010 Author Share Posted March 7, 2010 Tested the second half as well. Changed the redirect a different file on the server. It only shows a / and nothing else. <?php echo $_SERVER['REQUEST_URI']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022729 Share on other sites More sharing options...
soycharliente Posted March 7, 2010 Author Share Posted March 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022734 Share on other sites More sharing options...
cags Posted March 7, 2010 Share Posted March 7, 2010 Excellent, glad it's working. I must admit I've had strange caching issues with .htaccess before, I'm not entirely sure what causes them. Quote Link to comment https://forums.phpfreaks.com/topic/194301-redirect-traffic-except-two-files/#findComment-1022736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.