2015-09-15 98 views
2

的一個網站,我需要從 域名重定向加www TO域以www 和 HTTP到HTTPShtaccess的排除特定的文件夾

最終URL必須始終https://www.myshop.com ... 我解決了這個成功這個命令:

# if http, redirect to https 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# if without www, redirect to www (301) 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] 

問題是我必須排除特定的文件夾。 要排除的URL是:http://www.mydomain.de/myfolder/filename.php

這意味着:如果此URL被請求,則不得有重定向。

我發現其他教程沒有工作,對不起:-(

任何幫助的感謝和問候......

回答

0

你可以有一個跳過重定向規則這2條重定向規則,你必須:

RewriteEngine On 

# skip myfolder/filename.php from any redirects below 
RewriteCond %{THE_REQUEST} /myfolder/filename\.php[?/\s] [NC] 
RewriteRule^- [L] 

# if http, redirect to https 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# if without www, redirect to www (301) 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] 
+1

很大,..這解決方案的工作! – Phil

0

也許類似的東西

RewriteEngine on 

# if http, redirect to https 

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

# if without www, redirect to www (301) 
RewriteRule ^http://www.mydomain.de/myfolder/filename.php$ - [L] 
RewriteRule ^.*\filename.php$ http://www.mydomain.de/myfolder/filename.php [R=301,L] 
0

將這樣的內容添加爲第一個規則集可能會有所幫助。 (可想重溫那些[L,R]選項雖然。

# check if myfolder is contained 
RewriteCond %{REQUEST_URI} ^[^/]*/myfolder(/.*)?$ 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# if http, redirect to https 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# if without www, redirect to www (301) 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] 
+0

對不起,這並沒有爲我工作 – Phil

相關問題