我们正试图对某些url实施HTTPS,对其他网站实施HTTP。 我们也在重写url,所以所有的请求都通过我们的index.php。 这是我们的.htaccess文件。
# enable mod_rewrite RewriteEngine on # define the base url for accessing this folder RewriteBase / # Enforce http and https for certain pages RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # rewrite all requests for file and folders that do not exists RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
如果我们不包含最后一条规则(RewriteRule ^(。*)$ index.php?query = $ 1 [L,QSA]),那么HTTPS和HTTP规则可以很好地工作。 当我们添加最后三行时,其他规则将停止正常工作。
例如,如果我们尝试转到https:// www.domain.com/en/customer/login,则会redirect到http:// www.domain.com/index.php?query=en/customer/login。
这就像在redirect完成之前以及在指示redirect的[L]标志之后应用的最后一个规则是应用的最后一个规则。
UPDATE
我们在所有的规则中join了[NS]标志,但是没有任何区别。
你的前两条规则是第一次触及它,然后提出一个额外的请求(因为301),这将重新进入第三个RewriteRule。 试试这个:我为你的“checkout”path添加了一个exception:
# enable mod_rewrite RewriteEngine on # define the base url for accessing this folder RewriteBase / # Enforce http and https for certain pages RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/(en|fr)/(customer|checkout)(.*)$ [NC] RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
希望有所帮助!
你期待什么样的行为?
https://site.com/en/customer/login不会受到.htaccess中的第一条或第二条规则的影响,并且由于/ en / customer / login不是系统上的文件或目录,所以将会重写。
http://site.com/en/customer/login会受到您的第一条规则的影响,并会被redirect到https://site.com/en/customer/login 。 由于它被redirect了,现在它是一个新的响应,不会受到你的.htaccess中的第一个或第二个规则的影响,并且会匹配最后一个testing(/ en / customer / login不存在作为文件或目录)它会重写。
http://site.com/zh/somethingelse不会受到你的第一条或第二条规则的影响,并且由于/ en / somethingelse不存在,它会重写url。
https://site.com/zh/somethingelse不会受到第一条规则的影响,将被redirect到http://site.com/en/somethingelse 。 由于它被redirect,这是一个新的回应,不会受到.htaccess中的第一个或第二个规则的影响,并且会匹配最后一个testing(/ en / somethingelse不存在作为文件或目录),它会改写。