apache重写搜索网址

时间:2013-04-09 12:10:33

标签: php apache .htaccess url-rewriting

我有一个方法get

的简单表单
<form method="get" action="search.php">
<input type="text" name="category_name" value="cars">
<input type="text" name="location" value="newyork">
</form>

重定向到此链接:

http://my-site.com/search.php?category_name=cars&location=newyork

我会做一个重写规则:

http://my-site.com/cars/newyork.html

我已尝试使用此代码但无效:

RewriteEngine on
RewriteRule (.*)/(.*)\.html$ search.php?category_name=$1&location=$2 [R=301,L]

1 个答案:

答案 0 :(得分:0)

包括您拥有的规则,请尝试添加以下规则:

RewriteCond %{THE_REQUEST} ^GET\ /search\.php\?category_name=([^&]+)&location=([^&\ ]+)
RewriteRule ^ /%1/%2.html? [L,R=301]

此外,您可能需要为您拥有的规则添加几个条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)\.html$ search.php?category_name=$1&location=$2 [R=301,L]
相关问题