将某些页面重定向到HTTPS

时间:2014-02-02 09:54:16

标签: .htaccess

首先,我将我的/ example文件夹指向主域。现在,我想将一些页面重定向到HTTPS。请,任何人都可以建议我代码:

# com upload yonlendirme
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteCond %{REQUEST_URI} !^/example/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /example/$1 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteRule ^(/)?$ example/index.php [L]

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

#force https for certain pages    
RewriteCond %{HTTPS} !=on
RewriteRule ^(index\.php?route=account/register|index\.php?route=account/login|index\.php?route=account/account|index\.php?route=checkout/checkout)$ https://%{HTTP_HOST}%{REQUEST_URI}[L,R]

1 个答案:

答案 0 :(得分:0)

您无法在重写规则中与查询字符串(?之后的所有内容)进行匹配。您需要在重写条件中匹配%{QUERY_STRING}变量:

RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} ^route=(account/register|account/login|account/account|checkout/checkout)
RewriteRule ^index.php$ https://%{HTTP_HOST}%{REQUEST_URI}[L,R]

您可能还希望将该规则移至htaccess文件的顶部,以便路由到example文件夹不会干扰重定向。