2015-09-15 102 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

相关问题