简体   繁体   English

301 重定向,更改 url 中的参数,相同的域和文件

[英]301 redirect, change parameter in url, same domain and file

I have duplicate problem so I need to do some redirects, I understand as there are parameters I need to use Query_String, however as I don't want to change page, only the parameters, I have no idea我有重复的问题,所以我需要做一些重定向,我知道我需要使用 Query_String 的参数,但是因为我不想更改页面,只有参数,我不知道

I need to change a url like this:我需要更改这样的网址:

    /svenska/utflykter/tur-from.php?trop=trop&ciudad=Marbella&tour=Sevilla

to

    /svenska/utflykter/tur-from.php?ciudad=Marbella&tour=Sevilla

As you can see I only want to take away trop=trop however not on all pages, only on the page in question.正如你所看到的,我只想去掉 trop=trop 但不是在所有页面上,只在有问题的页面上。

Any idea, I have searched, thanks任何想法,我已经搜索过,谢谢

This probably is what you are looking for:这可能就是你要找的:

RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)ciudad=([^&]+).*&tour=([^&]+)(?:&|$)
RewriteRule ^/?svenska/utflykter/tur-from\.php$ /svenska/utflykter/tur-from.php?ciudad=%1&tour=%2 [R=301,QSD]

It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up.最好从 302 临时重定向开始,然后在确定一切设置正确后才将其更改为 301 永久重定向。 That prevents caching issues while trying things out...这可以防止在尝试时出现缓存问题......

This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file).此实现将在 http 服务器主机配置或分布式配置文件(“.htaccess”文件)中类似地工作。 Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host.显然重写模块需要在http服务器中加载并在http主机中启用。 In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.如果您使用分布式配置文件,您需要注意在主机配置中完全启用它的解释,并且它位于主机的DOCUMENT_ROOT文件夹中。

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess").还有一个一般性的评论:你应该总是喜欢将这样的规则放在 http 服务器主机配置中,而不是使用分布式配置文件(“.htaccess”)。 Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server.那些分布式配置文件增加了复杂性,通常是意外行为的原因,难以调试,而且它们确实降低了 http 服务器的速度。 They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).它们仅在您无法访问真正的 http 服务器主机配置(阅读:非常便宜的服务提供商)或坚持编写自己的规则的应用程序(这是一个明显的安全噩梦)的情况下作为最后一个选项提供。

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

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