将管理页面隐藏为子域

发布于 2025-01-06 14:05:18 字数 359 浏览 1 评论 0原文

我有一个网站,有一个管理页面(例如 admin.php),通常通过 mydomain.com/admin.php 访问,

我希望能够做的是使用 htaccess 来映射 “admin.mydomain.com”到“mydomain.com/admin.php”,这样用户永远不会知道它是一个“文件”。

也就是说,如果有人从外部尝试访问“mydomain.com/admin.php”,我希望它为 404。

现在,对于更困难的部分:admin.php 页面将希望将链接提供为“/admin.php? param=value”等,所以我需要查看引荐来源网址(???)才能使其按预期工作。

htaccess 可以做到这一点吗?知道从哪里开始吗?

I have a site that has an admin page (eg admin.php) that is normally accessed via mydomain.com/admin.php

What I was hoping to be able to do is to use htaccess to map
"admin.mydomain.com" to "mydomain.com/admin.php" in such a way that the user would never know that it was a 'file'.

That is, if someone externally tried to access "mydomain.com/admin.php", I want it to 404.

Now, for the even hard part: the admin.php page will want to serve links as "/admin.php?param=value", etc and so I'd need to look at the referrer (???) to let this work as expected.

can htaccess do this? Any idea on where to start?

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

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

发布评论

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

评论(2

街角迷惘 2025-01-13 14:05:18

如果您为 admin.mydomain.com 设置了一条记录,其 IP 地址与 mydomain.com 以及相同的 DocumentRoot 相同,

然后可以在 .htaccess 中这样做:

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^(admin\.) [NC]
RewriteRule ^ %1php [L]

RewriteCond %{REQUEST_URI} admin\.php$ [NC]
RewriteRule ^ - [R=404,L]

If you have set up a record for admin.mydomain.com with the same IP Address as mydomain.com as well as the same DocumentRoot,

Then this can be done like this in your .htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^(admin\.) [NC]
RewriteRule ^ %1php [L]

RewriteCond %{REQUEST_URI} admin\.php$ [NC]
RewriteRule ^ - [R=404,L]
南巷近海 2025-01-13 14:05:18

我真的不明白你想做什么(或者为什么你绝对需要页面mydomain.com/admin.php)。

如果您试图向用户“隐藏”它,为什么不实际创建一个子域,将文件放在子域中,在整个子域上实现安全性,然后就不需要搞乱重定向、引荐来源网址或查询字符串了。

为了安全起见,您可能需要执行类似这样的操作:

在您的 .htaccess 中put:

AuthUserFile /path/to/htpasswd/file/.htpasswd
AuthGroupFile /dev/null
AuthName "MyDomain Admin Area"
AuthType Basic
require valid-user

使用生成器创建文件 .htpasswd,例如 this

然后你无需向用户隐藏该页面,因为如果没有正确的用户名和密码,他们将得到 403。

I don't really understand what you are trying to do (or really why you absolutely need to have the page mydomain.com/admin.php).

If you are trying to "hide" it from the users, why not actually create a subdomain, place the file in the subdomain, implement security on the entire subdomain and then there is no need for messing around with redirections, referrers or query strings.

For security you might want to do something like this:

In your .htaccess put:

AuthUserFile /path/to/htpasswd/file/.htpasswd
AuthGroupFile /dev/null
AuthName "MyDomain Admin Area"
AuthType Basic
require valid-user

Create the file .htpasswd using a generator such as this

Then you will have no need to hide the page from the user because without the correct username and password, they will get a 403.

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