我想将包含符号和数字、字符的 URL 重定向到其他一些 URL 和...末尾包含 %00
的 URL 需要重定向到另一个 URL。
例子:
www.example.com/asdnsadnas%00
重定向到另一个 URL。
%00
在重定向 URL 中不被接受,请帮助我。
最佳答案
您如何处理这实际上取决于您所指的其他“符号和数字”以及它们在 URL 中出现的位置。
由于 RewriteRule
pattern 与 %-decoded URL 路径匹配并且 %00
为 NULL 然后要在 URL 路径中捕获 %00
,您可以尝试匹配 THE_REQUEST
,它包含请求的原始第一行(不是%-解码)。
www.example.com/asdnsadnas%00
redirect to another URL.
例如,在根 .htaccess
文件的顶部附近尝试以下操作:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /asdnsadnas%00\ HTTP
RewriteRule ^asdnsadnas /another-url [R,L]
RewriteRule
模式 只检查 URL 的第一部分,直到 %00
。
如果您只是想重定向 /asdnsadnas
并简单地忽略该 URL 路径之后的所有内容,那么您不需要显式检查 %00
,因此您可以删除 RewriteCond
指令。
www.example.com.nz/XYZABC%00
needs to redirects towww.example.com.nz/insurance-hub-page/xsserror/ XYZABC
- any letter or symbols etc but I need any URL at the end%00
need to redirect to another URL.
(我假设目标 URL 中的 space 只是拼写错误?)
在这种情况下,您不一定需要匹配 %00
(您不想要的“字符”)。只需具体说明您确实想要匹配的字符(这可能是一个较小的子集)。
例如,以下内容会将 /XYZABC
重定向到 /insurance-hub-page/xsserror/XYZABC
。尾随 %00
被忽略。
RewriteRule ^(\w+) /insurance-hub-page/xsserror/$1 [R,L]
...but I need any URL at the end
%00
need to redirect to another URL.
不确定你的意思是什么?
if URL contains any special charcters or symbols etc need to redirects to another url Example:
www.example.com/%28dsajkd%20nkasd%20daskdasj%00
您可以检查请求的 URL 是否包含任何 % 编码的字符,这似乎适合您的示例:
RewriteCond %{THE_REQUEST} %
RewriteRule ^ /another-url [R,L]
关于linux - 无法重定向包含 %00 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44064272/