【问题标题】:Http Error 500 with this htaccess rule [closed]带有此 htaccess 规则的 Http 错误 500 [关闭]
【发布时间】:2013-03-30 18:32:15
【问题描述】:

我想将任何请求从 http://www.domain.com/folder1/folder2/mytitle-1.html 重定向到 http://www.domain.com/folder1/folder2/script.php?id=1&code=5

我不明白为什么下面的规则不起作用。我在folder2的htaccess文件中添加了它

RewriteEngine on
RewriteRule ^folder1/folder2/mytitle-1.html$ /folder1/folder2/script.php?id=1&code=5 [L]

【问题讨论】:

  • 您真的收到 505 错误代码吗?那个不是很常见。您的服务器是否支持重写 URL?也许这就是问题所在。规则似乎没问题。
  • mod_rewrite 是否启用?
  • 是的,我认为它支持 htaccess 作为返回 print_r(apache_get_modules()) 返回一个包含 mod_rewrite 的列表
  • 不是 505 而是 500 错误代码
  • 规则似乎正确并且启用了 mod_rewrite 会怎样?

标签: php .htaccess redirect url-rewriting http-redirect


【解决方案1】:

您可以在根目录的一个 .htaccess 文件中尝试这样做:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !script\.php [NC]
RewriteRule  ^folder1/folder2/mytitle-1\.html/? /folder1/folder2/script.php?id=1&code=5 [L,NC]

选项:

如果.htaccess 文件位于/folder2,将上面的RewriteRule替换为这个:

RewriteRule  ^mytitle-1\.html/? /folder1/folder2/script.php?id=1&code=5 [L,NC]

对于永久且可见的重定向,请将 [L,NC] 替换为 [R=301,L,NC]

【讨论】:

  • @StephaneKouakou 好吧,我的回答有什么问题?您问题中的规则不起作用,因为它在/folder2 中。在我的回答中,这种情况有一个选项。
  • 是的,非常感谢您的回复!你是对的,我认为服务器可能有一些配置问题。问题是我无法访问 Apache 错误日志,所以我有点迷失在哪里出了问题! +1!反正
  • @StephaneKouakou 让我知道您是否需要对我的答案进行任何修改,只要您能找出错误所在。同时,尝试将 [L,NC] 替换为 [R,L,NC] 进行测试,以便查看替换 URL。我想这会有所帮助。
猜你喜欢
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
  • 2017-06-07
  • 2014-10-22
相关资源
最近更新 更多