Apache的重写规则传递整个URL作为参数 [英] Apache RewriteRule pass entire URL as a parameter
问题描述
目前我的Apache 重写规则
只传递原始URL路径作为查询参数来重写URL。
我如何将整个URL(包括计划性和权威性等)作为参数来重写URL?
我知道%{REQUEST_URI}
只传递的路径,我看不到那些传递整个URL的Apache的环境变量。
我一些初学者的Apache配置,所以原谅任何无知就我而言,
谢谢!
下面是我目前的配置:
#
#开启重写
#
RewriteEngine叙述上
#
#条件重写URL。检查URL的路径是一个有效的REST URI路径
#
的RewriteCond%{REQUEST_URI} ^(?:[^#?] *)(:1 / V [0-9] +(?:\ [0-9] +)*)(?:/ [AZ] +) (?:/ [AZ] +)(?:?/ [^?/#] *)(?:[?^#] *)$
#
#重写URL,发送REST路径作为参数传递给指定的版本。
#
重写规则^(?:[^#?] *)(?:/(V [0-9] +(?:\ [0-9] +)*))((?:/ [AZ] +)( ?:/ [AZ] +)(?:?/ [^?/#] *)(?:[^#?] *))$的https://localhost/rest/$1/index.php request_uri_path = HTTPS ://本地主机/ REST / $ 1 / $ 2 [QSA,NC,L,R = 307]
目前我已经很难codeD链接到查询参数,以便网址
的https://本地主机/ REST / V1 /用户/显示/ 12345
变成了:
<$p$p><$c$c>https://localhost/rest/v1/index.php?request_uri_path=https://localhost/rest/v1/users/show/12345
您可以使用此规则来获得完整的网址查询参数:
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} HTTPS S上(S)|
重写规则^的index.php request_uri_path = HTTP%1://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
如果您在Apache 2.4,那么你可以使用%{REQUEST_SCHEME}
变量:
的RewriteCond%{} REQUEST_FILENAME!-f
?重写规则^的index.php request_uri_path =%{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
Currently my Apache RewriteRule
only passes the path of the original URL as a query parameter to the rewritten URL.
How do I send the entire URL (including scheme and authority etc) as a parameter to the rewritten URL?
I know %{REQUEST_URI}
only passes the path, and I can’t see any Apache environment variables that do pass the entire URL.
I’m something of a beginner to Apache configuration so excuse any ignorance on my part,
thanks!
Here’s my current config:
#
# Enable Rewrite
#
RewriteEngine On
#
# Condition for rewriting the URL. Check the URL's path is a valid REST URI path
#
RewriteCond %{REQUEST_URI} ^(?:[^?#]*)(?:/v[0-9]+(?:\.[0-9]+)*)(?:/[a-z]+)(?:/[a-z]+)(?:/?[^/?#]*)(?:[^?#]*)$
#
# Rewrite the URL, sending the REST path as a parameter to the specified version.
#
RewriteRule ^(?:[^?#]*)(?:/(v[0-9]+(?:\.[0-9]+)*))((?:/[a-z]+)(?:/[a-z]+)(?:/?[^/?#]*)(?:[^?#]*))$ https://localhost/rest/$1/index.php?request_uri_path=https://localhost/rest/$1/$2 [QSA,NC,L,R=307]
Currently I’ve hardcoded the url into the query parameters so the URL
https://localhost/rest/v1/users/show/12345
becomes:
https://localhost/rest/v1/index.php?request_uri_path=https://localhost/rest/v1/users/show/12345
You can use this rule to get full URL as query parameter:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ index.php?request_uri_path=http%1://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
If you're on Apache 2.4 then you can make use of %{REQUEST_SCHEME}
variable:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php?request_uri_path=%{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
这篇关于Apache的重写规则传递整个URL作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!