wordpress - 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>
解决方案
根据这篇文章,您可以将.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
.
推荐阅读
- mysql - 是否可以通过比较两个表来更新触发器中的值?
- mysql - MySQL 按另一个表的 min 更新一个表
- css - CSS背景颜色在Safari中不起作用
- python - 如何在 Python 中调用函数内部的函数
- android - 暂停开放测试后,我的应用的 Google Play 评论是否会公开显示?
- discord - 向服务器的所有成员添加角色的代码
- statistics - 我想知道我所做的统计分析是否有意义
- elasticsearch - 在弹性搜索上不起作用的术语
- android - 未处理的异常:键入“列表”
' 不是 'String' 类型的子类型 无法获取 json 数据 - swift - 视图中的 AVFoundation 摄像头