For IP canonicalization, I'm told I need to redirect the IP address of the site to the domain name. I'm running a standard WordPress install that already comes with it's own .htaccess file. I modified it below by adding the "Redirect" line:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 http://12.34.56.789 http://www.domainname.com
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However, it's not working. Anyone know what is wrong?
Thanks!
What is a 301 redirect in WordPress? A 301 redirect, or permanent redirect, is an HTTP status code for permanently moving a web page to a different URL. If someone types the old URL into their browser or clicks on a link that points to the old URL, your site will seamlessly take them to the new URL that you specify.
Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
You generally don't want to mix Redirect
(mod_alias) with RewriteRule
(mod_rewrite) because they both get applied to the same URI and will clobber each others changes sometimes. Just stick with mod_rewrite because you have wordpress rules that already use it.
Replace the
Redirect 301 http://12.34.56.789 http://www.domainname.com
with:
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
Jon Lin's answer worked for me but I had to use
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
instead of
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With