mod_rewrite:如何处理查询字符串中的url?

时间:2013-09-12 13:52:25

标签: apache mod-rewrite

我有这样的网址: 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_encoded: http://www.domain.tld/check/http%3A%2F%2Fwww.otherdomain.tld

两个版本都不起作用。我总是得到404错误说 The requested URL /check/http://www.otherdomain.tld was not found on this server.

我是mod_rewrite的新手,并尝试了以下规则:
RewriteRule check/(.*)$ /index.php?url=$1
适用于任何非类似url的参数(例如test),但不适用于类似URL的参数。

我们非常感谢您解决此规则。

提前致谢。

马克

1 个答案:

答案 0 :(得分:0)

  1. 您是否在服务器上启用了Mod重写?

  2. 您是否在该规则之前写过“RewriteEngine On”? 您的htaccess文件应如下所示:

  3.   

    RewriteEngine On

         

    RewriteRule check /(.*)$ /index.php?url=$1

    要检查Apache服务器上是否未启用mod_rewrite,只需在.htaccess文件中输入一些随机内容,因为它应该会破坏所有网站。

相关问题