如何在htaccess中转义通配符中的字符

时间:2017-12-21 12:01:47

标签: .htaccess

我有一个htaccess文件,用于通过短链接赚钱,如下代码:

RewriteEngine On
RewriteRule (.*) http://shortlink.com/s/N9IpzM7J?s=$1 [R=301]

但是使用上面的代码,它会将example.com/https://google.com重定向到http://shortlink.com/s/N9IpzM7J?s=https:/google.com,注意它在https://丢失了一个斜杠,在我看来,它可能是一个特殊字符htaccess但我不知道如何逃避它。

所以我想问一下如何让上面的代码能够将example.com/https://google.com重定向到http://shortlink.com/s/N9IpzM7J?s=https://google.com

  

由于this post我将链接缩短服务的网址替换为shortlink.com!

1 个答案:

答案 0 :(得分:1)

如果要捕获完整URI,则应使用RewriteCond指令。

Apache会自动将多个斜杠剥离为RewriteRule指令中的单个斜杠。

RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ http://shortlink.com/s/N9IpzM7J?s=%1 [R=301,L]