【发布时间】:2019-02-04 22:35:46
【问题描述】:
在 .htaccess 文件中:
# Enable mod_rewrite
RewriteEngine on
# Rewrite file name
RewriteRule ^dome.htm$ dome.php [L,QSA]
# Force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
强制 SSL 和 WWW 效果很好,除了重写文件名,从下面的 URL 发出的请求返回到https://www.example.com/dome.php 的真实文件名:
example.com/dome.htm
www.example.com/dome.htm
https://example.com/home.htm
访问以上网址时如何保留https://www.example.com/dome.htm。
【问题讨论】:
标签: apache .htaccess url-rewriting url-rewrite-module