Preg_Replace Preg_Match 重定向到 WordPressDirectory
我已经成功解决了将 WordPress 的 wp-admin 目录从 site_url() 移动的需要
。 wp-admin/
到
MY_ADMIN_URL 。 wp-admin/
相当于
site_url() 。 /wp-content/plugins/myplugin/wp-admin/
经过几个月的自学实验,一切正常,并在这个论坛上找到了答案。但最后一件事我无法独自完成。
我需要阻止对 site_url() 中每个文件的访问。 / wp-admin/
并将每个重定向到其等效位置:
MY_ADMIN_URL 。 wp-admin/
但我无法通过在 preg_match preg_replace 中识别 wp-admin 目录来做到这一点,因为这些文件位于原始位置和新位置中名为 wp-admin 的目录中,我无法更改该目录。
我也无法对 url 进行硬编码,因为 site_url() 的实际 uri 以及因此 MY_ADMIN_URL 对于每次安装都明显不同。
更糟糕的是,即使我能理解,我也无法理解预赛的复杂性。
请有人(!)帮我想出一段 php 代码,上面写着:
如果有人尝试访问
site_url() 。 wp-admin/filename.php
将它们发送到
MY_ADMIN_URL 。 wp-admin/filename.php
非常感谢。
我真诚地在论坛中寻找答案,并试图拼凑出一个答案。但失败了。
I have managed to solve the need to move the wp-admin directory of WordPress from:
site_url() . wp-admin/
to
MY_ADMIN_URL . wp-admin/
which is equivalent to
site_url() . /wp-content/plugins/myplugin/wp-admin/
Everything is working, after months of self-taught experimentation, and answers found on this forum. But there is one last thing I just cannot manage to do on my own.
I need to block access to every file in site_url() . / wp-admin/
and redirect each one to its equivalent in:
MY_ADMIN_URL . wp-admin/
but I cannot do it by identifying the wp-admin directory in a preg_match preg_replace, because the files are in a directory with thename wp-admin in both the original and new location, which I cannot change.
I also cannot hard code a url, because the actual uri of site_url(), and therefore MY_ADMIN_URL is obviosuly different for every installation.
To make matters worse, even if I could, I cannot fathom the boggling complexity of pregmatch.
Could someone please(!) help me come up with a piece of php code that would say:
if someone tries to go to
site_url() . wp-admin/filename.php
send them to
MY_ADMIN_URL . wp-admin/filename.php
Many many thanks in advance.
I genuinely looked right through the forums for an answer, and tried to cobble one together. But failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用锁定 WP 管理员
此插件将锁定 WP 管理员。它可以隐藏 wp-admin 和 wp-login 以及向登录系统添加 HTTP 身份验证。它可以更改登录 URL。
Consider using Lockdown WP Admin
This plugin will lockdown WP Admin. It can hide wp-admin and wp-login as well as add HTTP auth to the login system. It can change the login URL.