Domain name in mod_rewrite RewriteRule

对着背影说爱祢 提交于 2019-12-24 11:19:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!