【问题标题】:Mod Rewrite variable contains a url with special charactersMod Rewrite 变量包含带有特殊字符的 url
【发布时间】:2010-07-04 05:50:02
【问题描述】:

我最近发现了 mod rewrite,我想知道这是否可能 重写包含出站 url 的变量。

到目前为止,它根本不起作用。我认为这是由于变量中的特殊字符引起的,我不知道如何解决这个问题。

到目前为止我的 .htaccess 代码:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^url/(\w+)/?$ link.php?url=$1 [L]

我想重写:

http://www.example-site.com/url/http://www.affiliate-site.com/dir/index.php?page=home

收件人:

http://www.example-site.com/link.php?url=http://www.affiliate-site.com/dir/index.php?page=home

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    \w 只是 a-z、A-Z 和 0-9

    这应该可以解决问题:

    RewriteRule ^url/(.+)/?$ /link.php?url=$1 [L]
    

    这份备忘单可以提供帮助:
    http://regexlib.com/CheatSheet.aspx

    【讨论】:

    • 嗨,Kerry,谢谢,确实有效。但是,我遇到了另一个问题,当我输入“affiliate-site.com”并在我的 php 文件中回显 GET 变量时,它显示为“http:/www.affiliate-site.com”。请注意,双斜杠输出为单斜杠。并且当 url 包含查询“?”时,它会切断 url 中的查询。所以“affiliate-site.com/dir/index.php?page=home”变成了“http://www.affiliate-site.com/dir/index.php”。知道为什么会这样吗?我怎么能解决它?最好的问候
    • 至于去掉双//,你是在URL上做stripslashes()吗?至于查询字符串,是的,它认为 ?是一个查询字符串。为了解决这个问题,我会读入并替换 $_SERVER['REQUEST_URI'] 中的当前 URL。这可以让您获得您正在寻找的网址,然后使用php.net/manual/en/function.parse-str.php 来获取您需要的变量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多