开发者

Is there a way to rewrite ?search= to /news/ in .htaccess?

开发者 https://www.devze.com 2023-03-10 03:05 出处:网络
Probably not.. but.. I there a way to rewr开发者_JAVA百科ite ?search= and make it read /news/ in .htaccess?

Probably not.. but..

I there a way to rewr开发者_JAVA百科ite ?search= and make it read /news/ in .htaccess?

So mydomain.com/?search=frogs would be: mydomain.com/news/frogs


Yes, you need to set a rewrite rule in .htaccess that does an HTTP redirect to cause the browser to request the new URL. I would recommend a 301 (permanent redirect) response code unless this is temporary, in which case use 302.

RewriteEngine on
RewriteCond %{QUERY_STRING} ^search=(.*)$
RewriteRule ^$ /news/%1? [L,R=301]

Should work, although I haven't tested. Here's a good rundown of some of the issues redirecting a URL with a querystring to a URL without one.

EDIT: after testing, changed the first argument of the RewriteRule from ^/$ to ^$. Should work now for URLs like example.com/?search=foo.


simples...

RewriteRule ^/news/(.*)$ index.php?search=$1 [NC,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消