【问题标题】:301 redirect not working with ip address301重定向不适用于IP地址
【发布时间】:2014-08-21 14:06:33
【问题描述】:

我在我的开发服务器上工作。 它没有域名,而是我过去通过 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]

当我尝试使用我的 live 站点 并且在 localhost 中它正在工作时,同样的事情。

【问题讨论】:

  • 尝试使用http 前缀,例如http://11\.10\.11\.19$

标签: php regex .htaccess redirect


【解决方案1】:

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

这在两种情况下都可以解决问题:

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

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 2013-10-31
    • 2010-12-08
    • 1970-01-01
    • 2015-12-30
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    相关资源
    最近更新 更多