Yazmin
Yazmin

Reputation: 1194

301 Redirect for IP address with standard WordPress .htaccess file

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!

Upvotes: 6

Views: 16722

Answers (2)

gravityboy
gravityboy

Reputation: 817

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]

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143936

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]

Upvotes: 11

Related Questions