【问题标题】:Redirect 301 in .htaccess causes 500 server error (Redirect to non-URL).htaccess 中的重定向 301 导致 500 服务器错误(重定向到非 URL)
【发布时间】:2011-07-16 11:09:09
【问题描述】:

有这样的错误。

Redirect 301 规则添加到.htaccess 文件时,例如:

Redirect 301 "/page1.html" "/dir1/"

我的网站因 500 服务器错误而失败,并且在 apache 错误日志中出现此错误:

[Wed Mar 16 11:08:52 2011] [alert] [client 127.0.0.1] /home/htdocs/site.com/www/.htaccess: Redirect to non-URL

Mod rewrite 已安装,也尝试提供不带引号的 url。

在生产服务器上这个 .htaccess 工作正常,但在本地会导致麻烦

任何想法,请)


这条规则有效

Redirect 301 "/page1.html" "http://www.site.com/dir1/"

但我需要一种方法来提供相对路径而不是完整的 url(生产服务器以这种方式工作)

【问题讨论】:

    标签: .htaccess apache2


    【解决方案1】:

    请试试这个,它按预期工作。

     <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      Redirect 301 /our_clients/nike /project/nike-nofyme-campaigns
     </IfModule>
    

    【讨论】:

      【解决方案2】:

      我有同样的问题,对我来说这也不起作用:

      RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]
      

      对我有用的是删除前导斜杠,并添加带有 ? 的软尾斜杠,如下所示:

      RewriteRule ^(page1.html)/?$ dir1/page.html [R=301,L]
      

      【讨论】:

        【解决方案3】:

        将所有Redirect 301 规则更改为:

        RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]
        

        现在工作。但它如何在生产中发挥作用?

        【讨论】:

          【解决方案4】:

          对我来说,我遇到了完全相同的问题。在“/mypage”前面添加“http://domain.com”有效;我仍在测试以使其在没有的情况下正常工作,就像在我的生产服务器上一样。所以我在本地测试环境中的 .htaccess 是这样的:

          破碎: 重定向 301 /mypage /directory1/sub-directory/mypage/

          固定: 重定向 301 http://mydomain.com/mypage http://mydomain.com/directory1/sub-directory/mypage/

          【讨论】:

          • @user675891 感谢您的回复,但我需要能够在我的开发和测试环境中使用相同的 .htaccess 文件,因此将 url 重写为完整不是一项功能 :) RewriteRule ^/page1.html$ /dir1/page.html [R=301,L]已解决的问题
          猜你喜欢
          • 1970-01-01
          • 2014-01-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-01-30
          • 2020-11-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多