网站根目录下新建.htaccess 文件
写入以下内容
方法一
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]方法二
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^demo.ahaoyw.com [NC,OR]
RewriteCond %{HTTP_HOST} ^demo1.ahaoyw.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]PS:其中demo.ahaoyw.com和demo1.ahaoyw.com为网站域名
NC代表“不区分大小写”
OR表示“或者” R:redirect重定向
L:last,表示已是最后一条规则,.htaccess文件解析将退出;
如果.htaccess 伪静态规则不生效,需要编辑站点配置文件或者httpd.conf修改如下配置
Options FollowSymLinks AllowOverride None
改为如下
Options FollowSymLinks AllowOverride All
开启mod_rewrite扩展
LoadModule rewrite_module modules/mod_rewrite.so
测试结果

更多 .htaccess用法可以参考 Apache .htaccess常用方法代码

