简体   繁体   English

www不重定向到非www .htaccess WordPress

[英]www not redirecting to non-www .htaccess Wordpress

I have an issue with my www not redirecting to non-www after setting up SSL and I can't figure it out, there are so many rules already set so IDK what is messing me up. 设置SSL后,我的www不能重定向到非www,这是一个问题,我无法弄清楚,已经设置了太多规则,因此IDK困扰了我。

Any help would be greatly appreciated! 任何帮助将不胜感激!

Here is the current section of .htaccess configuration that I believe is giving issues: 这是我认为正在产生问题的.htaccess配置的当前部分:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [E=WPR_SSL:-https]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [E=WPR_ENC:_gzip]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_|wp-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_) [NC]
RewriteCond %{HTTP_USER_AGENT} !^(facebookexternalhit).* [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}.html%{ENV:WPR_ENC}" -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* "/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}.html%{ENV:WPR_ENC}" [L]
</IfModule>



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
</IfModule>

I'm not an expert in this by any means, but I don't see where you're attempting the redirect. 无论如何,我都不是专家,但是我看不到您在尝试重定向的地方。 This has always worked for me: 这一直对我有用:

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

I've always put at the top of my .htaccess, but I'm speaking from limited experiences - again not an expert here. 我一直将.htaccess放在首位,但是我的经验有限-再次不是专家。

Hope this helps! 希望这可以帮助!

EDIT: While I think this should work for you, I'm not sure if it's best practice. 编辑:虽然我认为这应该为您工作,但我不确定这是否是最佳实践。 I'd reccomend waiting for someone else, more knowledgeable, to answer before making changes to your site. 我建议您等待其他人(知识渊博)来回答,然后再对您的网站进行更改。 I'll be following this question looking for other answers as well. 我也会关注这个问题,寻找其他答案。

Also what are your WordPress Address and Site Address set to in Settings -> General ? 另外,您在设置->常规中设置的WordPress地址和站点地址是什么? If you use your preferred non-www version there, that should take care of it in my experience. 如果您在此处使用首选的非www版本,那么根据我的经验应该可以解决。

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

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