我对.htaccess
文件有问题。我有一个像http://example.com/auction/category.php?lvl_1=texnologia
这样的URL。我在.htaccess
文件中使用代码:
RewriteEngine On
RewriteRule ^([^/]*)$ /auction/category.php?lvl_1=$1 [L]
它可以很好地工作: http://example.com/texnologia
- 但是,也想使用
http://example.com/auction/category.php?lvl_1=texnologia&lvl_2=gaming
进入http://example.com/texnologia/gaming
。 - 和
http://example.com/auction/category.php?lvl_1=texnologia&lvl_2=gaming&lvl_3=konsoles
去http://example.com/texnologia/gaming/konsoles
。
在我较早的代码下,我提出:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /auction/category.php?lvl_1=$1&lvl_2=$2 [L]
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /auction/category.php?lvl_1=$1&lvl_2=$2&lvl_3=$3 [L]
但是,我遇到了500个错误。
这样的事情应该做:
(您需要确保/auction/category.php
与任何规则不匹配,否则您最终会重定向循环(
RewriteEngine On
RewriteRule ^([^/]*)$ /auction/category.php?lvl_1=$1 [L]
RewriteCond %{REQUEST_URI} !/auction/category.php
RewriteRule ^([^/]*)/([^/]*)$ /auction/category.php?lvl_1=$1&lvl_2=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /auction/category.php?lvl_1=$1&lvl_2=$2&lvl_3=$3 [L]