我有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
感谢您提供的任何帮助。
答案 0 :(得分:0)
将此代码放入.htaccess:
ErrorDocument 404 /wordpress/404.php
RewriteEngine On
# first redirect everything to http://mysite.com/net, recognized by WP permalink
RewriteCond %{HTTP_HOST} ^www\.(mysite\.(?:net|com))$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# forward everything to wordpress folder
RewriteCond %{HTTP_HOST} ^mysite\.(com|net)$
RewriteRule ^$ wordpress [L]