.htaccess重写505错误循环

时间:2014-07-28 12:06:38

标签: php regex apache .htaccess mod-rewrite

我正在尝试改写:

mydomain.com/category.php?id=cat

mydomain.com/cat

我使用了以下.htaccess代码,但它一直显示505错误:

RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?id=$1 [L]

我在另一个页面上读到这是因为页面保持循环,但我无法弄清楚如何修复代码。

4 个答案:

答案 0 :(得分:1)

保持这样的规则:

RewriteEngine On

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /category.php?id=$1 [L,QSA]

答案 1 :(得分:0)

试试这个。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/ category.php?id=$1 [L]
</IfModule>

答案 2 :(得分:0)

您需要为RewriteCond

添加category.php以进行优化重写
RewriteEngine On
RewriteCond %{REQUEUST_URI} !^ /category.php/(.*)
RewriteRule ^(\w+)/ category.php?id=$1 [L]

答案 3 :(得分:0)

好的,这应该有效:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/category.php
RewriteRule ^(.*)$ category.php?id=$1 [R=301,L]

演示:http://ht6.valhook.com/cat

相关问题