alex3 Posted March 30, 2010 Share Posted March 30, 2010 Hi, I have this rewrite rule that detects if my VPS is being accessed via it's IP rather than an FQDN: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^12\.123\.123\.123 RewriteRule ^/(.*)$ http://hostname.domain.tld/$1 [R=301,L] </IfModule> And I have this as the hostname entry in my VHosts file for domain.tld: <VirtualHost *:80> # VHost for VPS info ServerName hostname.domain.tld ServerAlias hostname.domain.tld DocumentRoot /home/username/www/domain.tld/public/hostname </VirtualHost> When I visit 12.123.123.123 in my browser, I get shown the index.html of the hostname dir, but I don't get a hard redirect (as I believe I should with R=301), but I still see the IP in the address bar. I can't find any reason why the flags should be ignored, so why is the RewriteRule being carried out, but the flag ignored? Any help is immensely appreciated! Cheers, Alex Quote Link to comment https://forums.phpfreaks.com/topic/196932-r301-flag-being-ignored/ Share on other sites More sharing options...
alex3 Posted April 1, 2010 Author Share Posted April 1, 2010 Little bump, help still needed Quote Link to comment https://forums.phpfreaks.com/topic/196932-r301-flag-being-ignored/#findComment-1035171 Share on other sites More sharing options...
alex3 Posted April 9, 2010 Author Share Posted April 9, 2010 Bump.. Quote Link to comment https://forums.phpfreaks.com/topic/196932-r301-flag-being-ignored/#findComment-1039348 Share on other sites More sharing options...
cags Posted April 11, 2010 Share Posted April 11, 2010 RewriteRule ^/(.*)$ http://hostname.domain.tld/$1 [R=301,L] The pattern is probably not matching I don't believe there would be a forward slash at the start. Try removing it... RewriteRule ^(.*)$ http://hostname.domain.tld/$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/196932-r301-flag-being-ignored/#findComment-1039919 Share on other sites More sharing options...
alex3 Posted April 12, 2010 Author Share Posted April 12, 2010 Had been unbelievably stupid and was editing the wrong .htaccess for a start (SO stupid). Once I was editing the right one, removing the slashes worked, thank you so very much indeed Quote Link to comment https://forums.phpfreaks.com/topic/196932-r301-flag-being-ignored/#findComment-1040484 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.