使用htaccess尝试301重定向时无限循环

时间:2015-08-02 14:16:31

标签: php apache .htaccess mod-rewrite redirect

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

例如,我想将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]

旧的网址被谷歌索引,所以我需要这个重定向。

由于

1 个答案:

答案 0 :(得分: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]