2013-04-09 110 views
0

我有一个简单的形式与方法得到阿帕奇重写搜索URL

<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] 
+3

的第一个URL是浏览器发送HTML GET表单的格式 - 您不能更改该服务器端。 – CBroe 2013-04-09 12:26:15

+0

如何解决?这是可能的PHP重定向? – Mike 2013-04-09 13:04:10

+0

请求到达服务器后,您可以执行显式重定向。或者你在客户端执行,而不是以正常方式发送表单,而是使用JS读取值并手动创建URL。 – CBroe 2013-04-09 13:15:40

回答

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]