htaccess url 作为参数 [英] htaccess url as parameter
问题描述
大家好,提前致谢,我正在尝试添加一个 url 作为参数,但我不能.我的规则是:
Hi all and thanks in advance, I'm trying to add a url as a parameter but I can not. My rule is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^info/([a-zA-Z0-9|]+)/(.*)/(.*)$ info.php?user=$1&text=$2&url=$3
在浏览器中:http://localhost/example/info/peter/hi guy/http://www.example.com
返回数组$_GET
php
[user] => peter
[text] => hi guy / http:
[url] => www.example.com
什么是正确的:
[user] => peter
[text] => hi guy
[url] => http://www.example.com
希望得到您的帮助,谢谢
I hope your help thanks
推荐答案
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^info/([a-zA-Z0-9|]+)/([^/]*)/(.*)$ info.php?user=$1&text=$2&url=$3 [B,QSA]
[^/]
表示任何不是斜杠的字符".这自然意味着文本"不能包含任何斜杠,但您的 URL 将正确匹配.
[^/]
means "any character that's not a slash". Naturally this means that "text" cannot contain any slashes, but your URL will be matched correctly.
另请注意 [B]
,它是您可以添加到重写规则的众多选项之一.[B]
意味着任何 &
和一些其他字符都将被转义.因此,如果您作为参数的 URL 具有查询字符串,则可以在 $_GET['url']
中读出,否则其参数将被解释为新查询字符串的一部分.
Also note the [B]
which is one of many options you can add to a rewrite rule. [B]
means that any &
s and some other characters will be escaped. So if the URL that you're as a parameter has a query string, it can be read out in $_GET['url']
where its parameters would otherwise be interepreted as part of the new query string.
这篇关于htaccess url 作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!