将管理页面隐藏为子域
我有一个网站,有一个管理页面(例如 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您为
admin.mydomain.com
设置了一条记录,其 IP 地址与mydomain.com
以及相同的DocumentRoot
相同,然后可以在 .htaccess 中这样做:
If you have set up a record for
admin.mydomain.com
with the same IP Address asmydomain.com
as well as the sameDocumentRoot
,Then this can be done like this in your .htaccess:
我真的不明白你想做什么(或者为什么你绝对需要页面
mydomain.com/admin.php
)。如果您试图向用户“隐藏”它,为什么不实际创建一个子域,将文件放在子域中,在整个子域上实现安全性,然后就不需要搞乱重定向、引荐来源网址或查询字符串了。
为了安全起见,您可能需要执行类似这样的操作:
在您的 .htaccess 中put:
使用生成器创建文件 .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:
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.