Search url automatically in mod_rewrite version

亡梦爱人 提交于 2019-12-12 01:36:59

问题


Is it possible to set a forms action property automatically with mod_rewrite after clicking on a search button?

normal url is this: http://www.website.com/search.php?search=name

mod_rewrite url is this: http://www.website.com/search/name.html

I know that it is possible to set a mod_rewrite version of the page with htaccess, but how would I have the form go directly to the mod_rewrite url?

Regards


回答1:


This should work:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /search\.php\?search=(.*)\ HTTP
RewriteRule ^ /search/%2.html? [R=301,L]

RewriteRule ^search/(.*).html$ /search.php?name=$1 [L]

It should automatically turn the normal link into the mod_rewrite link.



来源:https://stackoverflow.com/questions/23681669/search-url-automatically-in-mod-rewrite-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!