简体   繁体   English

Wordpress .htaccess防止子文件夹重写其自己的网址

[英]Wordpress .htaccess preventing sub folder from rewriting its own urls

So I have been looking all over for a while, and cannot seem to find a particular solution I am looking for. 因此,我已经寻找了一段时间,似乎找不到我正在寻找的特定解决方案。 I have seen many articles showing how to fix problems with wordpress rewrite, but none fix my problem. 我看过许多文章,展示了如何通过Wordpress重写解决问题,但都没有解决我的问题。

I currently have Wordpress Installed in my / Root directory. 我当前在/根目录中安装了Wordpress。 the .htaccess looks like this. .htaccess看起来像这样。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^manager - [L,NC] <-- I added this from other examples.
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

So from what I can tell this tells wordpress, hey you will handle all the urls, for everything. 因此,据我所知,这告诉wordpress,嘿,您将处理所有内容的所有网址。 forever. 永远。 Seriously. 认真。 For ever and everywhere :P 永远无处不在:P

So the problem comes when I have a sub directory site.com/manager 所以问题出在我有一个子目录site.com/manager时

Here I would like to build a similar URL capturing method to manage what the user gets to see/access/etc. 在这里,我想构建一个类似的URL捕获方法来管理用户看到/访问/等的内容。 The line I added to the root .htaccess file (from what I have read) is suppose to tell wordpress, hey don't touch my damn /manager folder. 我添加到根.htaccess文件中的行(根据我的阅读)应该是告诉wordpress的,嘿,请不要触摸我该死的/ manager文件夹。

Wordpress being the sneaky greedy caregiver that it is fails to listen. WordPress是无法听的偷偷摸摸的贪婪的保姆。 ill go to test my site.com/manager/test (grabbing test and pulling info from sql with it) and wordpress takes over and throws me to the wordpress 404 page. 生病去测试我的site.com/manager/test(抓取测试并从sql中获取信息),然后wordpress接管并把我扔到wordpress 404页面。

my .htaccess in /manager is as follows for refrence, I am thinking I will need to do some rewrite stuffs here too, but for now just trying to prevent wordpress from being over bearing :). 我在/ manager中的.htaccess文件如下所示,我想我也需要在这里做一些重写工作,但现在只是为了防止wordpress过于疲劳:)。

DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php)$">
Order allow,deny
allow from all
</FilesMatch>

Any ideas, thoughts, comments, concerns would be much appreciated. 任何想法,想法,评论,关注将不胜感激。

Thank you. 谢谢。

SO after digging deeper and looking into this further I found a fix. 因此,在深入研究并进一步研究之后,我找到了解决方法。 Not sure it is the BEST solution but its working. 不确定这是最佳解决方案,但是否能正常工作。

Root (/) .htaccess 根(/).htaccess

#Manager - A customer content manager
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
#end Manager

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This appears to over ride wordpress like needed. 这似乎超过了需要的WordPress。

Manager (/manager) .htaccess 经理(/经理).htaccess

DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php|install.php)$">
Order allow,deny
allow from all
</FilesMatch>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /manager/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

The top portion isn't required but I added this for file protection/security. 顶部不是必需的,但是我为文件保护/安全性添加了它。

Summary: 摘要:

I used the %{REQUEST_URI} to selectively remove a sub-folder, to apply this to more sub-folders I would add another 我使用%{REQUEST_URI}来有选择地删除一个子文件夹,并将其应用于更多子文件夹,我将添加另一个

RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]

I then input the information in the sub-directory's .htaccess file for url rewriting. 然后,我将信息输入子目录的.htaccess文件中以进行url重写。 From here I can manipulate the URL converting it into a Array list for further sorting and database calling. 从这里,我可以操纵URL并将其转换为Array列表,以进行进一步的排序和数据库调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM