.htaccess参数重定向

时间:2018-02-04 23:07:05

标签: apache .htaccess mod-rewrite

我的.htaccess文件存在问题。我有一个像http://example.com/auction/category.php?lvl_1=texnologia这样的网址。我使用.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错误。

1 个答案:

答案 0 :(得分:0)

这样的事情应该做:

(您需要确保/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]