【问题标题】:Infinite loop when trying 301 redirect with htaccess [duplicate]尝试使用 htaccess 进行 301 重定向时出现无限循环 [重复]
【发布时间】:2015-10-24 16:52:10
【问题描述】:

我搜索了很多,但找不到解决方案。我正在尝试将带有参数的基于 php 的 url 重定向到 SEO 友好的 url。

例如,我想将 static.php?content_id=27 重定向到 /presentation/,但出现无限循环错误。

这是我的代码:

RewriteEngine On
RewriteBase /

RewriteRule ^presentation/$ static.php?content_id=27
RewriteCond %{QUERY_STRING} content_id=27
RewriteRule ^static\.php$ /presentation/? [L,R=301]

旧网址已被 google 索引,因此我需要此重定向。

谢谢

【问题讨论】:

标签: php apache .htaccess mod-rewrite redirect


【解决方案1】:

试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /static\.php\?content_id=27 [NC] 
RewriteRule ^ /presentation/? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /static.php?content_id=27 [NC,QSA,L]

【讨论】:

  • 哦,太好了,非常感谢。为什么我需要 %{REQUEST_FILENAME} !-f 和 %{REQUEST_FILENAME} !-d。谢谢:
  • Mm 不起作用,因为如果我为 static.php?content_id=14 添加相同的脚本,它仍然会从 static.php?content_id=27 获取内容
  • 你根本不明白我的问题:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 2017-04-15
  • 2015-08-15
  • 2014-02-03
  • 1970-01-01
相关资源
最近更新 更多