Search url automatically in mod_rewrite version

2019-09-01 09:24发布

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条回答
我命由我不由天
2楼-- · 2019-09-01 10:19

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.

查看更多
登录 后发表回答