基于HTTP_REFERER的.htaccess重定向 [英] .htaccess Redirect based on HTTP_REFERER

查看:497
本文介绍了基于HTTP_REFERER的.htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做什么,我上面已经说过,但我得到一个循环错误,有时一个500错误!

我要的是对用户请求的根网站首页页面重定向到 /欢迎 - 除非他们已经在浏览该网站

下面是我的code:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_REFERER}!^ MYDOMAIN \ .CO \ .UK $ [N]
的RewriteCond%{REQUEST_URI}的index.php [N]
重写规则^ $ /欢迎光临[L]
 

解决方案

你可能会得到500错误,因为 [N] 不是一个有效的<$ C C>的RewriteCond 标志$,你在想 [NC] (任何情况下)?

此外,您有一个直接违背了规则的匹配条件:

 的RewriteCond%{REQUEST_URI}的index.php
 

表示, URI 必须有一个的index.php 在里面。尽管规则本身:

 重写规则^ $ /欢迎光临[L]
 

表示, URI 必须匹配 ^ $ 这意味着它必须完全 / 。而 / 绝不会的index.php ,所以规则是当下无效。也许你在想任/或?

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_REFERER}!^ MYDOMAIN \ .CO \ .UK $ [NC]
重写规则^(指数\ .PHP)?$ /欢迎光临[L]
 

这将不区分的引荐匹配 mydomain.co.uk ,并改写为 / 的index.php /欢迎

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]

解决方案

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

这篇关于基于HTTP_REFERER的.htaccess重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆