【发布时间】:2013-09-24 16:32:32
【问题描述】:
我在使用 htaccess 时遇到问题,希望有人可以帮助我:
我在/wordpress 目录中有一个wordpress 安装。所以如果有人访问“www.mysite.com”或“mysite.com”我想重定向到/wordpress。
我在服务器上有一些网站,例如/deleted.html
所以我添加了一个 404-Errorpage: ErrorDocument 404 /wordpress/404.php 。
如果您访问 mysite.com/deleted.html,则所有内容都适用于 404 页面,但如果您访问 www.mysite.com/deleted.html,则无法正常工作。
在这种情况下,首先会出现 301 重定向,然后会加载 404 页面。这对 Google 来说是个问题,因为他们无法检测到该页面已被删除。
看起来是这样的:
curl -I -L http://www.mysite.com/deleted.html
HTTP/1.1 301 Moved Permanently
Date: Tue, 24 Sep 2013 16:02:18 GMT
Server: Apache/2.2.25 (Unix)
Location: http://mysite.com/deleted.html
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 404 Not Found
Date: Tue, 24 Sep 2013 16:02:18 GMT
Server: Apache/2.2.25 (Unix)
X-Powered-By: PHP/5.2.17
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
X-UA-Compatible: IE=edge,chrome=1
Content-Type: text/html; charset=UTF-8
这是我的 .htaccess
ErrorDocument 404 /wordpress/404.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ wordpress
RewriteCond %{HTTP_HOST} ^(www.)?mysite.net$
RewriteRule ^(/)?$ wordpress
感谢您提供的任何帮助。
【问题讨论】:
-
这是因为
permalinkWP 中的设置。最好总是首先将所有内容重定向到配置的 WPhttp://mysite.com。 -
你是对的。永久链接设置是问题所在。我现在通过为 Errorpage 创建一个静态 html 文件来解决它,并将元重定向到我的 wordpress 404 页面。
<meta http-equiv="refresh" content="0; url=http://mysite.com/wordpress/404.php">但是现在用户可以看到一秒钟的静态页面,然后发生重定向。所以要正确地做到这一点,我需要解决永久链接问题.. -
这更像是一个黑客解决方案。让我在我的回答中给你一些建议,如果你愿意,可以使用它。
标签: wordpress apache .htaccess redirect