.htaccess 更改文件扩展名并同时强制为 https

.htaccess change file extention and force to https at the same time

我想使用 .htaccess 将我的 url 从 .php 更改为 .html 另外,我需要这个页面强制成为 https 以上要求是针对特定页面而不是整个页面...

eg. http://domain/filename/XXX.php => https://domain/filename/XXX.html

有谁知道如何解决这个问题?谢谢

结合https和扩展修改的一些规则就可以了

# Prevent endless loop
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# and redirect php to html
RewriteRule ^(.+)\.php$ https://%{HTTP_HOST}/.html [L]

# Enforce https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]

# Finally serve content
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html /.php [L]