问题
The task is to get referer domain and send it to my script by RewriteRule. My decision is
SetEnvIf Referer "^https?://(.*)/" myref=$1
RewriteRule ^(.*)$ script.php?referer=%{ENV:myref}
It works right but I wonder if there are any ways to do it (perhaps with RewriteCond)?
回答1:
mod_rewrite has a variable named %{HTTP_REFERER}
. It contains what you expect. You can use it like this:
RewriteCond %{REQUEST_URI} !^/script\.php$
RewriteRule ^ script.php?referer=%{HTTP_REFERER} [L]
See the documentation for more information.
来源:https://stackoverflow.com/questions/28517833/domain-name-in-mod-rewrite-rewriterule