繁体   English   中英

Wordpress .htaccess www重定向失败

[英]Wordpress .htaccess www redirect fail

我刚刚被要求帮助管理慈善WordPress网站。 它使用的是http,我想将.htaccess重定向修改为www。 .htaccess文件看起来像是沼泽标准文件,在开始处添加了404:

ErrorDocument 404 /error.php
# 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

我已经尝试过几次添加www重定向代码,但是每次都会失败:

ErrorDocument 404 /error.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^l-a-m.org [NC]
RewriteRule ^(.*)$ http://www.l-a-m.org/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

我也尝试过将重定向块移出#WordPress代码,并将其放在文件的开头,但这也不起作用。

我是WordPress的新手,所以有人可以帮忙告诉我我要去哪里了吗?

Shim-Sao在他的评论中回答...修改.htaccess文件不起作用,因此我编辑了wp-config.php并添加了以下行:

define('WP_HOME','http://www.l-a-m.org');
define('WP_SITEURL','http://www.l-a-m.org');

/* That's all, stop editing! Happy blogging. */

尝试更换:

RewriteCond %{HTTP_HOST} ^l-a-m.org [NC]
RewriteRule ^(.*)$ http://www.l-a-m.org/$1 [L,R=301]

有:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

您还提到了先前的尝试“保持失败”。 您能否告诉我们出了什么问题,因为这可能也会导致上述方法失败。

你可以试试 :

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) http://www.example.com/$1 [QSA,L,R=301]

或强制https:

RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://www.example.com/$1 [QSA,L,R=301]

用所需的主机替换example.com

编辑重要事项:

在WordPress中,请勿使用.htaccess,请使用wp-config.php并使用正确的主机名修改两行:

define('WP_HOME','http://www.domainname.com');
define('WP_SITEURL','http://www.domainname.com');

暂无
暂无

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

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