简体   繁体   English

无参数重定向到URls

[英]Redirect to URls without parameters

thanks for helping newbies like me with your competent answers: I have a question regarding redirects from URls with parameters to new URls without parameters, probably using the .htaccess file. 感谢帮助像我这样的新手用你能胜任的答案:我有一个关于从带有参数的URls重定向到没有参数的新URls的问题,可能使用.htaccess文件。 I have tried answers on questions like this htacces to redirect without params 301 Redirect of old url with parameters to a path without parametes 我已尝试过像这样的问题的答案, 以重定向没有参数 301将旧网址的参数重定向到没有参数的路径

but I'm still unsure how to proceed correctly. 但我仍然不确定如何正确地进行。

So here is my problem: the old URL structure http://www.mysite.com/my-files/query-qry?origen=1&destino=&aerolinea=DE&proveedor=barceloviajes&clase=F&escalas= 所以这是我的问题:旧的URL结构http://www.mysite.com/my-files/query-qry?origen=1&destino=&aerolinea=DE&proveedor=barceloviajes&clase=F&escalas=

should redirect to this one: http://www.mysite.com/my-files/query-qry 应该重定向到这个: http//www.mysite.com/my-files/query-qry

to put it short: I want to add a 301 redirection without all parameters. 简而言之:我想在没有所有参数的情况下添加301重定向。 What is the best and fastest solution and is there a rule that can be applied? 什么是最好和最快的解决方案,是否有可以应用的规则?

Thank you very much for your help! 非常感谢您的帮助!

RewriteEngine On
RewriteCond %{QUERY_STRING} !="" #if there is a query string
RewriteCond %{QUERY_STRING} !^p=.* #wordpress users: allow post tempalinks
RewriteCond %{REQUEST_URI} !^/wp-admin.* #wordpress users: don't break admin
RewriteRule ^(.*)$ /$1? [R=301,L] #remove query string

http://briancray.com/posts/htaccess-hack-remove-url-query-strings/ http://briancray.com/posts/htaccess-hack-remove-url-query-strings/

To put it short: I want to add a 301 redirection without all parameters.

You can use this rule in your DOCUMENT_ROOT/.htaccess file: 您可以在DOCUMENT_ROOT/.htaccess文件中使用此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} .+
RewriteRule ^ %{REQUEST_URI}? [R=301,L] 

Better than using a final ?, you should use the qsdiscard flag QSD . 比使用final?更好,你应该使用qsdiscard标志QSD For your case : 对于你的情况:

RewriteCond %{QUERY_STRING} .+
RewriteRule ^my-files/query-qry my-files/query-qry [QSD,L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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