简体   繁体   English

我怎样才能重写所有网址,除了少数到https与mod重写

[英]how can i rewrite all urls except for a few to https with mod rewrite

I have made a site with codeigniter below is the current htaccess file: 我在下面创建了一个codeigniter的网站是当前的htaccess文件:

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. 我需要添加一些规则,以便网站仍能正常工作,但大多数网址都会重定向到https。 The urls that need to be exempt from this rule are: 需要免除此规则的网址是:

/about /faqs /terms-and-conditions /contact-us /privacy-policy / about / faqs / terms-and-conditions / contact-us / privacy-policy

All of these urls that are exempt should be accessed over normal http 所有这些免除的网址都应该通过普通的http访问

To redirect non-http request to https, use the %{HTTPS} in RewriteCond 要将非http请求重定向到https,请使用RewriteCond中的%{HTTPS}

RewriteCond %{HTTPS} off

If the request is https, this condition fails and the rule is skipped. 如果请求是https,则此条件失败并跳过规则。 Then to exempt paths, you can add them after 然后要免除路径,您可以在之后添加它们

RewriteCond %{REQUEST_URI} !/about /faqs /terms-and-conditions /contact-us /privacy-policy

Then finally, the redirect 最后,重定向

RewriteRule ^(.*)$ https://your-site.com/$1 [R,L]

You'll want to add these 3 lines above the rewrite conditions for the rule you have above that rewrites everything to index.php 您将要在上面的规则的重写条件之上添加这3行,将所有内容重写为index.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM