301重定向不使用ip地址

时间:2014-07-01 05:32:07

标签: php regex .htaccess redirect

我在我的开发服务器上工作。 它没有域名,而是我曾经通过IP地址访问它。我想从中制作重定向脚本 http://11.10.11.19/index.php to http://11.10.11.19/(给出的IP地址为样本)

.httaccess(开发服务器)

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ 11\.10\.11\.19$ [R=301,L]

.httaccess(实时服务器)

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ http://www.domainname.com [R=301,L]

当我尝试使用我的实时网站 localhost 时,它的工作正常。

1 个答案:

答案 0 :(得分:1)

听起来我想要将index.php重定向到域的根目录,无论您是通过IP还是按名称访问它。

在两种情况下都应该这样做:

RewriteEngine On
RewriteRule ^()index\.php$ $1 [L,R]