【问题标题】:301 redirect not working in .htaccess301 重定向在 .htaccess 中不起作用
【发布时间】:2016-03-29 12:12:40
【问题描述】:

我有两个域,autodromodifranciacorta.itfranciacortacircuit.com 都指向托管在此 IP 地址上的同一网站:94.23.64.40

现在我希望所有内容都在一个域下,所以我决定 301 将所有流量从 franciacortacircuit.com 重定向到 autodromodifranciacorta.it

这是我的 .htaccess 文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

重定向不起作用,我不知道为什么,因为语法对我来说是正确的。 .htaccess 文件已被处理,因为如果我在其中输入错字,我会收到服务器错误。

这有什么问题?

【问题讨论】:

    标签: .htaccess redirect mod-rewrite


    【解决方案1】:

    您的第二个 http_host 条件是错误的,如果当前主机是 franciacortacircuit.com,它永远不会匹配,您需要使用 OR 条件来匹配 2 个不同的主机。

     #Redirect Entire Site to New Domain
     RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
     RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
    RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
    

    【讨论】:

    • 不工作...我得到这个:内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。请联系服务器管理员 postmaster@autodromidifranciacorta.it 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。服务器错误日志中可能提供有关此错误的更多信息。 (如果你现在尝试,你会看到它工作,因为我暂时放置了一个 PHP 301 重定向。但我刚刚测试了你的配置,它不工作:()
    • @Alberto fontana - 我发布了一个可行的解决方案,但它已被版主删除,因此我无法再次发布。对不起。
    • 该死的……为什么被删除了?
    猜你喜欢
    • 2013-04-06
    • 2017-06-30
    • 2014-07-05
    • 2014-12-21
    • 2011-03-08
    • 2013-03-14
    • 1970-01-01
    相关资源
    最近更新 更多