我如何使用 mod rewrite 将除少数几个之外的所有 url 重写为 https
我用 codeigniter 创建了一个网站,下面是当前的 htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我需要添加一些规则,以便该网站仍然正常工作,但大多数 URL 都重定向到 https。需要免除此规则的网址是:
/about /常见问题解答 /条款和条件 /联系我们 /privacy-policy
所有这些豁免的 url 应通过正常的 http 访问
I have made a site with codeigniter below is the current htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I need to add some rules so that the site still works as normal but most URLs are redirected to https. The urls that need to be exempt from this rule are:
/about
/faqs
/terms-and-conditions
/contact-us
/privacy-policy
All of these urls that are exempt should be accessed over normal http
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将非 http 请求重定向到 https,请在 RewriteCond 中使用 %{HTTPS}
如果请求是 https,则此条件失败并跳过该规则。然后要免除路径,您可以在之后添加它们
最后,重定向
您需要在上面的规则的重写条件上方添加这 3 行,该规则将所有内容重写到 index.php
To redirect non-http request to https, use the %{HTTPS} in RewriteCond
If the request is https, this condition fails and the rule is skipped. Then to exempt paths, you can add them after
Then finally, the redirect
You'll want to add these 3 lines above the rewrite conditions for the rule you have above that rewrites everything to index.php