.htaccess Redirect based on HTTP_REFERER

荒凉一梦 提交于 2019-12-02 09:03:07

问题


I'm trying to do what I've said above but I am getting a looping error and sometimes a 500 error!

What I want is for users requesting the root 'Home' page of the site to be redirected to /Welcome - UNLESS they are already browsing the site.

Here's my code:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mydomain\.co\.uk$ [N]
RewriteCond %{REQUEST_URI} /index.php [N]
RewriteRule ^$ /Welcome [L]

回答1:


You're probably getting the 500 error because the [N] isn't a valid RewriteCond flag, are you thinking of [NC] (no case)?

Additionally, you have a condition that directly contradicts the rule's match:

RewriteCond %{REQUEST_URI} /index.php

Says the URI must have a /index.php in it. While the rule itself:

RewriteRule ^$ /Welcome [L]

Says the URI must match ^$ which means it must be exactly /. And / will never be /index.php, so the rule is instantly invalid. Maybe you're thinking of either/or?

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mydomain\.co\.uk$ [NC]
RewriteRule ^(index\.php)?$ /Welcome [L]

This will match the referer without case against mydomain.co.uk, and rewrite either / or /index.php to /Welcome



来源:https://stackoverflow.com/questions/12618445/htaccess-redirect-based-on-http-referer

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