.htaccess mod_rewrite 基于 IP 的重定向:如何将所有流量重定向到除我的 IP 之外的特定子目录?

发布于 2024-12-23 15:19:20 字数 391 浏览 0 评论 0原文

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

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

因此结构如下:

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 执行此操作有建议吗?

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.

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

So the structure is as follows:

mysite.com/blog // visitor access allowed

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

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

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

etc...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞慾 2024-12-30 15:19:20

您应该能够使用以下命令进行重定向:

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

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]
亢潮 2024-12-30 15:19:20

您应该创建一个处理特定重定向的页面,然后将您的 htaccess 文件编辑为如下所示:

Options +FollowSymlinks
RewriteEngine on
#not your IP
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.123
#make sure the rule allows everyone to access the redirect page
RewriteCond %{REQUEST_URI} !/redirect_page\.html$
#Send them to the redirect page
RewriteRule \.html$ /redirect_page.html [R=302,L]

rediret_page.html 可以有 js 或服务器端重定向来处理它们最终的位置,但这将迫使每个拥有不会通过处理重定向的特定页面访问您的 IP 地址。

You should create a page that handles the specific redirects, and then edit your htaccess file to be something like this:

Options +FollowSymlinks
RewriteEngine on
#not your IP
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.123
#make sure the rule allows everyone to access the redirect page
RewriteCond %{REQUEST_URI} !/redirect_page\.html$
#Send them to the redirect page
RewriteRule \.html$ /redirect_page.html [R=302,L]

The rediret_page.html can have either js or server-side redirection that handles where they end up, but it will force everyone who has not come on your IP address through a specific page that handles redirection.

无可置疑 2024-12-30 15:19:20

只需将您的 IP 地址添加到..

order deny,allow
deny from all
allow from xxx.xx.xxx

Just add your IP Address in..

order deny,allow
deny from all
allow from xxx.xx.xxx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文