本文介绍了国防部重写删除www和转%2520送入太空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WWW重定向到非工作正常,但转弯%2520所有出现的空间,使用QUERY_STRING看来,当我将它们合并失败。
我一派,并结合的RewriteCond和重写规则的SOed负载,但我无法找到一个例子,即使似乎接近这一个是如何工作的。所有我已经计算出的是,我可能滥用(。*)正则表达式。总的正则表达式并在这里mod_rewrite的小白 - !没有冷嘲热讽,请:-)在此先感谢

我已经试过这一点,相反的:

 的RewriteCond%(HTTP_HOST)^ www.mywebsite \\ .COM $
重写规则(。*)http://mywebsite.com/$1 [R = 301,L]
的RewriteCond%{QUERY_STRING} ^(。*)(2520%)(。*)$
重写规则^(。+)$ $ 1?%1 \\%3 [N,R = 301]


解决方案

这是网址都有它允许有限的字符集。不允许有空格为在URL中的字符,因此它们都带coded到 20%。类似地,%2520 是一个双连接codeD空间。

您为我优秀作品规则(你可以离开了周围的捕获组%2520 ,因为它是不必要的,但它不会破坏任何东西)。这将改变 http://example.com/minimalonecharacter?asdf%2520qwer http://example.com/minimalonecharacter?asdf%20qwer

我注意到,您使用的状态code 301 (永久重定向)这一点。我推荐的的具有永久重定向测试,直到一切都按你想要的工作。浏览器可能会缓存永久重定向,跳绳对服务器的请求。如果你作出错误的重写规则,这样的结果是缓存和未来的尝试奇怪的角度去你的第一次尝试。

Redirecting www to non is working fine, but turning all occurrences of %2520 to a space, using QUERY_STRING seems to fail when I combine them.I've Googled and SOed loads of combining RewriteCond and RewriteRule but I can't find an example that even seems close to how this one works. All I've worked out is that I'm probably abusing the (.*) regex. Total regex and mod_rewrite noob here - no snide comments please :-) Thanks in advance!

I've tried this, and the reverse:

RewriteCond %(HTTP_HOST) ^www.mywebsite\.com$
RewriteRule (.*) http://mywebsite.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^(.*)(%2520)(.*)$
RewriteRule ^(.+)$ $1?%1\ %3 [N,R=301]
解决方案

An url has a limited subset of characters it allows. Spaces are not allowed as a character in an url, and therefore they are encoded to %20. Similary, %2520 is a double encoded space.

The rule you provide works fine for me (you could leave out the capturing group around %2520 as it is unnecessary, but it doesn't break anything). It will transform http://example.com/minimalonecharacter?asdf%2520qwer to http://example.com/minimalonecharacter?asdf%20qwer.

I notice that you use status code 301 (permanent redirect) for this. I recommend not testing with a permanent redirect, until everything works as you want it to work. The browser might cache a permanent redirect, skipping a request to the server. If you make a wrong rewriterule, this result is cached and future attempts "strangely" point to your first attempt.

这篇关于国防部重写删除www和转%2520送入太空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 21:16