htaccess - HTTP到HTTPS和.HTML到/ [英] htaccess - HTTP to HTTPS and .HTML to /

查看:169
本文介绍了htaccess - HTTP到HTTPS和.HTML到/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 .htaccess 的帮助:

强制 http:/ / https://

AND

强制 .html /

到目前为止我所拥有的:

What I have so far:

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]


推荐答案

Options -MultiViews

RewriteEngine On
#1 This line checks if the https is off
RewriteCond %{HTTPS} ^off$
#then, redirect to https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [NC,L,R]
#2 this line checks if the request is /file.html
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
#then redirect /file.html to /file
RewriteRule ^ /%1 [NC,L,R]

#3 if the request is not for dir
RewriteCond %{REQUEST_FILENAME} !-d
#and the request is an existing filename
RewriteCond %{REQUEST_FILENAME}.html -f
#then rewrite /file to /file.html
RewriteRule ^([^/]+)/?$ $1.html [NC,L]

在上面的例子中,第一个条件当原始方案是HTTP时满足,然后处理规则。 HTTP转到HTTPS。第一轮重写处理在这里结束。

In the example above, the first condition is met when the original scheme is HTTP, and then the rule is processed. HTTP goes to HTTPS. The first Round of rewrite processing ends here.

在第二轮中,mod_rewrite接受URI /file.html并且规则将其重定向到/ file,因为/ file目录中不存在,因此我们需要将其重写为原始文件#3 ...

In the second round, mod_rewrite accepts the URI /file.html and the rule redirects it to /file, since the /file does not exist in directory, so we need to rewrite it to the original file #3...

这篇关于htaccess - HTTP到HTTPS和.HTML到/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆