首页 > 解决方案 > wordpress htaccess http www redirect to https non-www

问题描述

I have read so many posts on this my head is absolutely swimming and nothing I try seems to work properly. My site was http://www I have changed it in the wordpress settings to https:// (non-www) (I have an ssl certificate installed)

I have an existing .htaccess file.
I cant figure out how to adjust my existing .htaccess to redirect all requests to https:// (non-www) Can someone please give me the full code simply of what my htaccess should be ?

This is my existing htaccess file:

# 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
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

<Files 403.shtml>
order allow,deny
allow from all
</Files>

标签: wordpress.htaccesshttps

解决方案


根据这篇文章,您可以将.httaccess文件更改为重定向:

http://example.com
http://www.example.com
https://example.com


https://example.com

使用

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

只需#end wordpress.htaccess文件中添加此代码即可。
保存.htaccess文件后,记得将您的永久链接结构保存在settings->permalink.


推荐阅读