Jump to content

R=301 Flag Being Ignored


alex3

Recommended Posts

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

Link to comment
Share on other sites

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]

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.