Html Apache-重写URL
我有一个简单的html表单Html Apache-重写URL,html,regex,apache,get,rewrite,Html,Regex,Apache,Get,Rewrite,我有一个简单的html表单 <form class="form-search" method="get" action="search.php"> <input name="what" type="text" class="input-xlarge search-query" placeholder="what"> <input name="where" type="text" class="input-xlarge search-query" placeh
<form class="form-search" method="get" action="search.php">
<input name="what" type="text" class="input-xlarge search-query" placeholder="what">
<input name="where" type="text" class="input-xlarge search-query" placeholder="where">
<button type="submit" class="btn btn-primary search">search</button>
</form>
搜索
当我点击按钮时,URL是这样的,到目前为止一切都很好
我想要相同的功能,但我想将URL重写为
使用apache rewrite可以实现吗?我认为这应该可以实现
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([^/]+)/([^/]+) /search.php?what=$1&where=$2 [L]
使用此url
如果没有名为foo的文件夹和与文件名匹配的文件或目录,它将重定向显示请求结果。有很好的说明,可以准确地说明您要执行的操作
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/([^/]+)/([^/])+ /search.php?what=$1&where=$2 [NC]
应该这样做。您需要匹配请求,以便让浏览器加载
/foo/bar/
URL,然后在内部将其重写回查询字符串:
RewriteEngine On
RewriteCond %{THE_REQUEST} GET\ /+search\.php\?what=([^&]+)&where=([^&\ ]+)
RewriteRule ^ /%1/%2/? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/([^/]+)/?$ /search.php?what=$1&where=$2 [L,QSA]