【问题标题】:Create subfolder, not affected by WordPress创建子文件夹,不受 WordPress 影响
【发布时间】:2014-01-29 14:52:07
【问题描述】:

我在根目录下安装了一个 WordPress 站点。我在该站点的子文件夹 /shop 中添加了一个在线商店。 /shop 文件夹中有一个 index.php 文件和这个 .htaccess 文件:

#/shop/.htaccess
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?arg1=$1 [L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?arg1=$1&arg2=$2 [L]

一些示例有效的 URL 是:

http://www.mysite.com/shop/
http://www.mysite.com/shop/clothes
http://www.mysite.com/shop/shoes
http://www.mysite.com/shop/hats

这些网址显示得很好,但标头是 404,这会导致 Google 出现问题。

这里是请求头:

GET /shop/clothes/ HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://www.mysite.com/shop/
Cookie: __utma=152555369.2028364656.1389216381.1389279043.1389294490.4; __utmz=152555369.1389216381.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-1=editor%3Dtinymce%26hidetb%3D1%26libraryContent%3Dbrowse%26urlbutton%3Dnone%26wplink%3D1; wp-settings-time-1=1389277270; PHPSESSID=2df7073e57934fd781ab27c1c7b74245; __utmb=152555369.34.10.1389294490; __utmc=152555369; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_b2aba7eb0409bbc11fbbc4c2403dc2dc=admin%7C1389471226%7Cc07f299f80fe0ac1b15598636b08f66f
X-LogDigger-CliVer: client-firefox 2.1.7
X-LogDigger: logme=0&reqid=f7a4f2ac-3cfc-4a63-94e6-0b9233c7dfe6&
Connection: keep-alive

这是响应头:

HTTP/1.1 404 Not Found
Date: Thu, 09 Jan 2014 20:21:23 GMT
Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_perl/2.0.5 Perl/v5.8.8
X-Powered-By: PHP/5.3.13
X-Pingback: http://www.mysite.com/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Content-Length: 14381

在我的 /shop/index.php 文件中,我尝试手动输出状态为 200 的标头,但没有解决问题。

我尝试将以下内容添加到根 .htaccess 文件(WordPress 的)中,但没有奏效:

ErrorDocument 401 default

在根 .htaccess 文件(WordPress 的)中,我尝试在 WordPress 的 RewriteRules 之前、之后和内部添加这些命令,但我仍然得到 404 标头:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/shop/(.*)$
RewriteRule ^.*$ - [L]

/shop 文件夹和子文件夹的权限为 0755,文件的权限为 0644,都与 WordPress 安装具有相同的所有者/组。

感谢任何帮助。谢谢。

【问题讨论】:

  • 如果为了测试您将 WP .htaccess 重命名为其他名称,您还会得到 404 标头吗?
  • 刚试过,是的,将/.htaccess重命名为/.htaccessxxx后仍然出现404错误
  • 嗯,这不是因为 WP,而是因为 /shop 中的规则/代码
  • 你是对的。在 /shop/index.php 中,我删除了这两行,停止了 404 错误:require __DIR__ . '/../wp-blog-header.php'; get_header(); 但是现在页面没有标题,我需要找到另一种方式来显示它而无需重复代码。谢谢你的帮助。将此放入答案中,我会将其标记为正确。

标签: wordpress apache .htaccess mod-rewrite http-status-code-404


【解决方案1】:

测试是否确实是 WP 引起的:

  • 您可以将 WP .htaccess 重命名为其他名称,然后检查是否仍然得到 404 标头。

如果 WP .htaccess 仍然出现 404 错误,则很可能是由 /shop/ 文件夹中的规则/代码引起的。

【讨论】:

  • 如上所述,您是对的。在 /shop/index.php 中,我包含了这两行来输出模板的标题:require __DIR__ . '/../wp-blog-header.php'; get_header(); 删除它们会使 404 错误消失(并跟踪 WP 代码我明白了原因)。现在页面没有标题/样式,所以我需要找到另一种显示方式。再次感谢。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多