更新时间:2023-02-24 09:56:39
您可以使用此规则来获得完整的网址查询参数:
的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]