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:
对于IP规范化,我被告知我需要将站点的IP地址重定向到域名。我正在运行一个标准的WordPress安装,它已经附带了它自己的.htaccess文件。我通过添加“重定向”行修改了它:
# 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!
谢谢!
2 个解决方案
#1
9
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.
您通常不希望将Redirect(mod_alias)与RewriteRule(mod_rewrite)混合使用,因为它们都应用于相同的URI并且有时会破坏彼此的更改。只需坚持使用mod_rewrite,因为你已经使用了wordpress规则。
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]
#2
1
Jon Lin's answer worked for me but I had to use
Jon Lin的回答对我有用,但我不得不使用
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]
#1
9
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.
您通常不希望将Redirect(mod_alias)与RewriteRule(mod_rewrite)混合使用,因为它们都应用于相同的URI并且有时会破坏彼此的更改。只需坚持使用mod_rewrite,因为你已经使用了wordpress规则。
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]
#2
1
Jon Lin's answer worked for me but I had to use
Jon Lin的回答对我有用,但我不得不使用
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]