.htaccess mod_rewrite 基于 IP 的重定向:如何将所有流量重定向到特定子目录,除了我的 IP? [英] .htaccess mod_rewrite IP-based redirect: how to redirect all traffic to a specific subdirectory, except my IP?

查看:27
本文介绍了.htaccess mod_rewrite 基于 IP 的重定向:如何将所有流量重定向到特定子目录,除了我的 IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的访问者只能访问我网站(博客)的特定部分.如果他们尝试访问网站的其他区域,我希望他们重定向到博客部分.

I want my visitors to have access only to a specific part of my website (blog). If they try to access other areas of the website, I'd like them redirected to the blog section.

我还希望这适用于除我的 IP 地址之外的所有人.

I also want this to apply to everyone except to my IP address.

所以结构如下:

mysite.com/blog//允许访问者访问

mysite.com        // redirect to mysite.com/blog

mysite.com/forum  // redirect to mysite.com/blog

mysite.com/tools  // redirect to mysite.com/blog

etc...

您是否有关于如何通过 .htaccess mod_rewrite 执行此操作的建议?

Do you have a suggestion on how to do this via .htaccess mod_rewrite?

推荐答案

您应该能够使用以下内容进行重定向:

You should be able to redirect with the following:

RewriteCond %{REMOTE_HOST} !^123\.456\.789
RewriteCond %{REQUEST_URI} !^/blog/?
RewriteCond %{REQUEST_URI} /(.*)$
RewriteRule (.*) /blog [R=301,L]

这篇关于.htaccess mod_rewrite 基于 IP 的重定向:如何将所有流量重定向到特定子目录,除了我的 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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