无法访问非wordpress子目录,因为wordpress会以404错误
-
-
如果将WordPress根文件夹中的index.php重命名为index.bak会发生什么?目录仍然无法访问吗?What happens if you rename the index.php to index.bak in the WordPress root folder? Is the directory still not accessible?
- 0
- 2011-06-16
- Horttcore
-
您是否尝试过在子文件夹.htaccess中重新定义基本URL(使用此子文件夹获取值)?Have you tried to redefine the base url in your sub-folder .htaccess (with this sub-folder for value) ?
- 0
- 2011-08-05
- Cédric G
-
8 个回答
- 投票数
-
- 2011-06-17
我假设您将WordPress放在网站根目录中,而外部目录也在您的网站根目录中.发生这种情况的原因是.htaccess文件遵循层次结构.顶级.htaccess文件中的所有指令均会向下传输并应用于其下的所有目录.
在这种情况下,您可以执行以下其中一项操作:
-
将WordPress移到其自己的目录中. 请参阅: http://codex.wordpress.org/Moving_WordPress 如果将WordPress移到其自己的目录中,以便它在服务器目录层次结构中与其他目录处于同一级别,则WordPress重写规则不会影响其他目录.
-
RewriteEngine关闭-这通常可以正常工作.如果不起作用,请检查您是否未使用通配符DNS设置.如果您在DNS设置中有通配符*主机名记录指向您的Web服务器,则可能会导致.htaccess和子域崩溃.
-
在网站根目录的.htaccess文件中,在WordPress .htaccess指令上方添加以下内容:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR] RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR] RewriteRule ^.*$ - [L] </IfModule>
其中之一应该适合您.
I'm assuming that you put WordPress in your site root and the external directories are also in your site root. The reason this is happening is that .htaccess files follow a hierarchy. Whatever directives are in the top-level .htaccess file flow down and apply to all directories below it.
If this is the case, you can do one of several things:
Move your WordPress into its own directory. See: http://codex.wordpress.org/Moving_WordPress If you move WordPress into its own directory so that it is on the same level in your server directory hierarchy as the other directories the WordPress rewrite rules cannot affect the other directories.
RewriteEngine Off - this would normally work. If it isn't working check that you are not using a wildcard DNS setting. If you have a wildcard * hostname record pointing at your web server in your DNS settings it can cause havoc with .htaccess and subdomains.
In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR] RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR] RewriteRule ^.*$ - [L] </IfModule>
One of these should work for you.
-
-
谢谢!我已经尝试了很多事情,但这是适用于我的情况的唯一解决方案:受密码保护的子目录Thanks! I've tried so many things, but this is the only solution that worked for my case: password-protected subdirectory
- 3
- 2013-03-06
- Rado
-
也为我工作,关于它做什么以及为什么起作用的任何解释?Worked for me too, any explanation as to what it does and why it works?
- 2
- 2013-08-10
- Asaf
-
这对我有效..不是使用wordpress而是使用OpenCart并遇到相同的问题.一个解释将非常有帮助.This works for me.. not using wordpress but OpenCart and having the same problem. An explanation would be really helpful.
- 0
- 2014-08-28
- billynoah
-
-
- 2012-05-25
我看到此线程已有几个月的历史了,但以防万一您无法正常工作!
我有一个类似的问题,但是我的问题是wordpress安装位于子目录中,这阻止了URL访问根目录(WP安装目录之外)中的文件夹,但是仅当启用了永久链接时.为了解决这个问题,我从WP安装所在的子目录中复制了index.php和.htaccess(不可移动),并将它们都放置在根public_html(或您尝试在WP安装之外访问的任何子目录)中目录). .htaccess文件已经具有永久链接的重写条件:
RewriteEngine On RewriteBase /subdirectoryinstallfolder/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
启用永久链接进行刷新,它解决了所有问题.确保您对根文件夹的权限设置也正确,因为这过去曾给我带来麻烦.
I see this thread is a few months old, but just in case you never got it to work!
I had a similar issue, but my problem was that the wordpress install was located in the subdirectory which prevented URL access to folders within the root (outside the WP install directory), but only when permalinks were enabled. To solve this, I copied both index.php and .htaccess (copy not move) from the subdirectory where the WP install is located and placed them both in the root public_html (or whatever subdirectory that you're trying to access outside the WP install directory). The .htaccess file has the rewrite conditions for permalinks already:
RewriteEngine On RewriteBase /subdirectoryinstallfolder/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
Enable permalinks for refresh and it solved all issues. Make sure your permissions for the root folders are set correctly too as this has caused me problems in the past.
-
- 2012-09-13
当我将文件复制到同一服务器但具有不同的子目录文件夹时,因此当我尝试访问我的页面时,index.php可以正常工作,但其他页面却无法工作,并给我404错误.对不起,我英语不好!!
我只是查看htaccess的原文:
#开始WordPress RewriteEngine开 RewriteBase/ RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule./index.php [L] #END WordPress
然后将新的与
#开始WordPress RewriteEngine开 RewriteBase/子目录文件夹 RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule./subdirectoryfolder/index.php [L] #结束WordPress
when i copy my files into the same server but with different subdirectory folder so when i tried to access my pages, index.php is working fine but the other pages are not and giving me a 404 error. Sorry for my bad english!!
I just look into my htaccess the original:
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
and put the new one with
# BEGIN WordPress RewriteEngine On RewriteBase /subdirectoryfolder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subdirectoryfolder/index.php [L] # END WordPress
-
嗨@lizette.欢迎来到WPSE论坛.您可能想在此处查看[格式化的工作原理](http://stackoverflow.com/editing-help).Hi @lizette. Welcome to WPSE forums. You may want to check out [how formatting works](http://stackoverflow.com/editing-help) here.
- 0
- 2012-09-21
- Pothi Kalimuthu
-
- 2011-06-17
如果您仍然在禁用htaccess的情况下得到404,并且已经验证了路径并且知道文件在那里,那么剩下的唯一选择就是这三个...
选项...
- 服务器很有可能正在运行区分大小写的操作系统.这意味着如果您在输入路径时未使用确切的字符和大写字母,将无法正常工作.
- 权限:您可能对文件或文件夹或父文件夹具有错误的权限.尝试将文件,文件夹和父文件夹的权限更改为755.如果您具有ssh(终端)访问权限,请转到根目录并运行此" chmod -R 755mydir",这将递归设置所有用户的权限.
- 如果在这之后仍然遇到问题,则说明服务器配置存在问题(可能是Apache).您需要与您的托管服务提供商商谈.
如果这些都不起作用,那么您需要一个新主机.
If you are still getting 404's with the htaccess disabled and you have verified the paths and you know the files are there then your only options left are these three...
Options...
- Server is quite possibly running a case-sensitive operating system. Which means if you are typing in a path and not using the exact characters and casing it simply will not work.
- Permissions: You may have the wrong permissions on the file or folder or a parent folder. Try to change the permissions to 755 on the files, folders, and parent folders. If you have ssh (terminal) access to it then go to your root and run this "chmod -R 755 mydir" and that will recursively set the permissions for all of them.
- If you are still having a problem after all of that then you have a server config problem (Apache probably). You will need to talk to your hosting provider about it.
If none of that works then you need a new host.
-
- 2015-12-10
几乎拔掉头发编辑htaccess之后,我终于找到了适用于WordPress的解决方案.
在与WordPress相同的根目录上安装了codeiginter脚本后,我遇到了这个问题.
尝试了此处列出的所有技巧之后,与新脚本关联的页面上仍然出现404错误.
我注意到WordPress htaccess覆盖了脚本的htaccess.我还注意到,同一目录中的其他WordPress安装没有此404错误.
我只是在同一服务器目录中的新WordPress安装中采用了htaccess,并将其添加到脚本所在的文件夹中.外观如下:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /subdirectoryname/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subdirectoryname/index.php [L] </IfModule>
用目录名称替换 subdirectoryname 并将此htaccess文件放在脚本所在的文件夹中.
示例:如果站点安装在此处
public_html/
新文件夹位于
`public_html/example`
复制上面的htaccess并将其保存在"example"文件夹中,这应该可以工作.
After nearly plucking my hair editing the htaccess I finally found a solution that will work for WordPress.
I had this problem after installing a codeiginter script on the same root directory that WordPress is installed.
After trying all the tricks listed here I was still getting 404 errors on the pages associated with the new script.
I noted that the WordPress htaccess was overiding the script's htaccess. I also noted that other WordPress installations in the same directory did not have this 404 error.
I simply adopted the htaccess from the new WordPress installation in the same server directory and added it in the folder where my script is located. Here is how it looks like :
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /subdirectoryname/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subdirectoryname/index.php [L] </IfModule>
Replace subdirectoryname with the name of your directory and place this htaccess file inside the folder where your script is located.
Example : If the site is installed here
public_html/
and the new folder is located
`public_html/example`
copy the htaccess above and save it inside the folder 'example' and this should work.
-
- 2013-10-02
由于遇到类似问题,我已经多次查看了这里的响应.我在子目录中有文件,当我尝试访问它们时会抛出404错误.正如Kirsten Douglas所说,所有.htaccess内容都无法纠正它,Wordpress已经完成了工作.
我的解决方案
我找到了这个检查服务器上的error_log后的文章.我收到有关脚本错误uid的消息.我还注意到404并不是因为文件而被抛出,而是因为服务器无法提供500.html文件,即我有500错误.
结果是我以root用户身份创建了文件,并且需要将所有权更改为webfiles所有者.
我希望这对遇到同样问题的其他人有所帮助!
I've looked at the responses here a number of times as I'd run into a similar problem. I have files in a subdirectory that would throw a 404 error when I tried to access them. All the .htaccess stuff failed to rectify it, as Kirsten Douglas says, Wordpress does the job already.
My solution
I found this article after checking the error_log on the server. I was getting a message about wrong uid for scripts. I also noticed that the 404 wasn't being thrown because of the file, but because the server couldn't serve up a 500.html file i.e. I had a 500 error.
Turns out I'd created files as root, and needed to change ownership to the webfiles owner.
I hope this helps others who've had the same issue!
-
- 2011-06-16
您应该能够仅添加
RewriteCond
指令,以确保子文件夹中的请求将忽略WordPress规则.RewriteCond %{REQUEST_URI} !^/mysubdirectory # rest of WordPress rewrite rules
但是,您说即使使用no WordPress
.htaccess
,您仍遇到问题吗?子目录.htaccess
的内容是什么?You should be able to just add a
RewriteCond
directive that will make sure the WordPress rules are ignored for requests inside your subfolder.RewriteCond %{REQUEST_URI} !^/mysubdirectory # rest of WordPress rewrite rules
However, you say that even with no WordPress
.htaccess
you're experiencing the problem? What's the contents of your subdirectory.htaccess
?
我指的是以前问过的这个问题,没有适当回答: WordPress覆盖实际的子目录 并且 非" Wordpress"页面/代码出现404错误
我遇到了同样的问题,并且尝试了几乎所有在网上找到的内容.这肯定与在wordpress中启用永久链接有关. 但是,我在新的.htaccess文件中放了以下子目录:
关闭RewriteEngine
,问题仍然存在.即使我完全删除了wordpress .htaccess文件,问题仍然存在.
我还尝试了其他一些建议的解决方案,例如 错误文档401"未经授权的访问" 和 错误文档404"未经授权的访问" 和 重定向301/mysubdirectory http://www.mydomain.com/mysubdirectory/index.html 在各个地方都无济于事.
有人可以提供其他解决方案吗? 我可以解决的唯一方法是关闭永久链接,但我们需要将其打开.
谢谢
妮可