0

我有一个简单的表格,方法是 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]
4

1 回答 1

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]
于 2013-04-09T17:25:54.577 回答