.htaccess从www重定向到非www不正常[我尽了一切可能]



我已经用wordpress创建了一个网站,但当涉及到SEO时,我有这个问题需要解决,该域曾经链接到lawlytics.com订阅,我已经取消了订阅。我安装了wordpress,并将其附加到我的域中,该域位于ionos.com上,问题是当我尝试打开我的网站http://mywebsite.com时,它与安装的wordpress配合良好,但当我尝试使用该网站时,它会重定向到旧的lawlytics订阅网站。我在.htaccess文件中尝试了很多代码,比如

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)(.+)
RewriteRule .* https://%1/$0 [R,L]
RewriteCond %{HTTP_HOST} ^www.(.+)
RewriteRule .* https://%1/$0 [R,L]

和这个

# Redirects from HTTP to HTTPS. We use %{SERVER_PORT} as it's more reliable than %{HTTPS}
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Redirects www.example.com/... to example.com/...
RewriteCond %{HTTP_HOST} ^www.(.+)
RewriteRule .* https://%1%{REQUEST_URI} [R,L]
RewriteRule ^(.*).html$ $1.php [nc]

但当我的.htaces文件看起来像这个时,它们都不起作用

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]  
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
AddHandler x-mapp-php5.5  .php
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

这段代码在.htaccess的末尾。我的网站已经安装了SSL。

尝试在wp-config.php文件中的任何位置设置(或编辑(如果存在((:

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

在将网站移动到新的URL后,它对我起了很多作用,但这取决于具体情况。

最新更新