Apache mod_rewrite:如何处理查询字符串中的url?
我有这样一个URL:Apache mod_rewrite:如何处理查询字符串中的url?,apache,mod-rewrite,Apache,Mod Rewrite,我有这样一个URL: http://www.domain.tld/index.php?url=http://www.otherdomain.tld 现在我想使用mod_rewrite,以便将此url重写为如上所述的url: http://www.domain.tld/check/http://www.otherdomain.tld 我还尝试了url_编码: http://www.domain.tld/check/http%3A%2F%2Fwww.otherdomain.tld 两个版本都不起作用
http://www.domain.tld/index.php?url=http://www.otherdomain.tld
现在我想使用mod_rewrite,以便将此url重写为如上所述的url:
http://www.domain.tld/check/http://www.otherdomain.tld
我还尝试了url_编码:
http://www.domain.tld/check/http%3A%2F%2Fwww.otherdomain.tld
两个版本都不起作用。我总是收到一个404错误,说
请求的URL/检查/http://www.otherdomain.tld 在此服务器上找不到。
我对mod_rewrite完全是新手,并尝试了以下规则:重写规则检查/(.*)$/index.php?url=$1
它适用于任何非url类参数(例如,
test
),但不适用于url类参数
感谢您提供的任何帮助来修复此规则
提前谢谢
马克
要检查Apache服务器上是否未启用mod_rewrite,只需在.htaccess文件中输入一些随机内容,因为它会破坏所有网站。mod_rewrite已启用,并且该规则基本上已经适用,例如
http://www.domain.tld/check/test
但不使用URL作为查询参数。如果字符不是URL编码的,这将构成一个非法的URL,并且无法正确解析。是的,这就是我对该部分进行URL编码的原因。但它仍然不起作用……您是否尝试过保留规则以传递到index.php
,但从$\u服务器['REQUEST\u URI']
中获取值?在PHP项目中使用前端控制器时,在PHP中处理URL通常要容易得多,而不是让mod_rewrite来处理。我还没有检查PHP中的URL:RewriteRule是在htaccess文件中定义的,该文件还包括404页面的定义。如果我输入urlhttp://www.domain.tld/check/test
我可以看到我定义的页面。但是如果我输入http://www.domain.tld/check/http%3A%2F%2Ftest
我得到了一个404页面,但不是我定义的页面(通常可以使用),而是来自服务器的默认页面。如果我将RewriteRule更改为只调用index.php而不调用参数,也会发生这种情况。“重写日志”中没有此尝试的任何条目-它看起来很早就中断了…@zotto:必须是服务器处理URL时指出它无效的内容-您不能修剪https://
位吗?