2014-05-19 88 views
1

我有一個特殊的問題。我需要重寫所有轉到http => https的請求,並且我想修復url,如果它缺少www,所以我也有一個重寫規則。如何重寫不包含短語的所有非SSL請求?

現在,有一個例外,不應該重寫。如果請求的是 http://www.mydomain.com/API2 /...../ ..

下API2的一切不應該rewrited到https ...

這裏是我當前的.htaccess:

RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /index.php/$1 [L] 
# Start A2 Switcher Block 
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$ 
<IfModule mod_suphp.c> 
    AddHandler application/x-httpd-php-5.4.13 .php 
</IfModule> 
# End A2 Switcher Block 

任何人都可以幫忙嗎?

回答

1

有你這樣的代碼:

RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule !^api2/ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC] 

RewriteCond %{HTTPS} off 
RewriteRule !^api2/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC] 

RewriteCond %{HTTPS} on 
RewriteRule ^api2/ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^api2/ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /index.php/$1 [L] 

# Start A2 Switcher Block 
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$ 
<IfModule mod_suphp.c> 
    AddHandler application/x-httpd-php-5.4.13 .php 
</IfModule> 
# End A2 Switcher Block 
+0

完美,非常感謝! –

+0

不客氣,很高興它解決了。 – anubhava

相關問題