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

牧云@^-^@ 提交于 2019-12-12 03:29:19

问题


I want to change my url from .php to .html with .htaccess also, I need this page force becoming to https the above requirement are for the certain page not whole page...

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

do anyone know how to solve this problem? thanks


回答1:


Just combine some rules for https and extension modification

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

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

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


来源:https://stackoverflow.com/questions/37633958/htaccess-change-file-extention-and-force-to-https-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!