htaccess根据IP重定向

发布于 2024-09-25 16:08:52 字数 441 浏览 0 评论 0原文

假设我的服务器如下所示:

/www/.htaccess
/www/index.php
/www/temp/index.php

我的个人 IP(不是服务器的!)是 127.0.0.1*

(* 好吧,这是不可能的,但为了论证......)

我想重定向(301/302)除了 /temp/index.php 的 IP 之外的每个人

我当前的代码如下所示:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/temp/*$
RewriteRule \$ /temp/* [R=302,L]

但是我收到 500 错误。

Let's say my server looks like this:

/www/.htaccess
/www/index.php
/www/temp/index.php

And my personal IP (not the server's!) is 127.0.0.1*

(* ok, that's impossible, but for the sake of argument...)

I would like to redirect (301/302) everyone EXCEPT that IP to /temp/index.php

My current code looks like:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/temp/*$
RewriteRule \$ /temp/* [R=302,L]

However I get a 500 error.

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

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

发布评论

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

评论(1

执妄 2024-10-02 16:08:52

没关系,这些 htaccess 文件很难使用。我在主 index.php 文件中使用了一些 PHP 代码。

Never mind, these htaccess file are hard to work with. I used some PHP code in my main index.php file instead.

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