简体   繁体   中英

mod_rewrite: rewrite specific URL

I want to rewrite a specific URL, I'll show an example so you'll understand what I mean.

First, my current rewrite rule:

RewriteRule ^/?([a-zA-Z0-9/-]+)/?$ /index.php [NC,L]

Now I want this URL:

http://example.tld/foobar?test

Rewritten to:

http://example.tld/foobar

only for /foobar?test ! 仅用于/foobar?testEg not for /somethingelse?test and also not for /foobar?blah !

Thanks in advance!

I realized I want a 301 redirect from /foobar?test to /foobar , not a "traditional" rewrite. 我意识到我想要从/foobar?test/foobar的301重定向,而不是“传统”重写。 Hope that is possible.

RewriteCond %{QUERY_STRING}    ^test$
RewriteRule ^/foobar$          /foobar      [NC,R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM