[英].htaccess permanent redirect with query string
I want to have a permanent redirect where whoever visits the old url is automatically sent to the new one: 我想要一个永久重定向,凡是访问旧网址的人都会自动发送到新网址:
From: https://example.io/users?username=value To: https://example.io/value 从: https : //example.io/users?username= value到: https : //example.io/value
The new URL already works, but I just need the redirect. 新的URL已经可以使用,但是我只需要重定向。 I already have this code:
我已经有了以下代码:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ users.php?username=$1 [QSA,L]
I'd say this should roughly be what your question asks for: 我说这应该大致是您的问题要求的内容:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^username=(.+)$
RewriteRule ^/?users\.php/?$ /%1 [R=301]
Those lines should work likewise in the http servers host configuration or in dynamic configuration files (".htaccess"). 这些行应在http服务器主机配置或动态配置文件(“ .htaccess”)中同样起作用。
It redirects all incoming requests to the old URL " /users.php?username=value
. I fail to see how the code you posted should help here, which is why I wrote above rules from scratch instead of modifying yours. 它将所有传入的请求重定向到旧的URL“
/users.php?username=value
。我看不到您发布的代码在这里有什么帮助,这就是为什么我从头开始编写上述规则而不是修改您的规则的原因。
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). 还有一个一般性说明:您应该始终喜欢将此类规则放在http服务器主机配置中,而不要使用动态配置文件(“ .htaccess”)。 Those dynamic 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.