.htaccess参数重定向



我对.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=konsoleshttp://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]

最新更新