的.htaccess 301重定向没有GET变种变种、重定向、htaccess、GET

2023-09-02 20:37:36 作者:女人,我只对你霸道╮

对于一个网站,我目前正在对我们重定向我们的旧的URL的永久换新这样的: 重定向301 /oldfile.php http://www.site.com/show/newurl

For a website I'm currently working on we're redirecting our old URL's permanently to new ones like this: Redirect 301 /oldfile.php http://www.site.com/show/newurl

现在我遇到这种情况,即旧的URL有一个GET变种,如: 重定向301 /oldfile.php?var=name http://www.site.com/show/newurl

Now I come across this situation in which the old url has a get var like: Redirect 301 /oldfile.php?var=name http://www.site.com/show/newurl

这将重定向的oldfile新的URL再加上它增加了获取无功,因此重定向到: http://www.site.com/show/newurl?var=name

This will redirect the oldfile to the new url plus it adds the get var so it redirects to: http://www.site.com/show/newurl?var=name

我将如何设立这个重定向没有获取VAR?

How would I set up this redirect without the get var?

推荐答案

的mod_rewrite 可以去掉查询字符串:

mod_rewrite can strip off the query string:

RewriteEngine on
RewriteRule ^/?oldfile.php$ http://www.site.com/show/newurl? [R=301,L]