2017-05-11 25 views
1

我已經創建使用盡可能cookiless域這就好比cdn.domain.comhtaccess的重寫,如果子域不存在

和主網站,我有www.domain.com一個子域。無論我稱之爲www.cdn.domain.com。我使用cdn.domain.com調用圖像等

在這裏你可以看到實際的htaccess設置

<IfModule mod_rewrite.c> 

RewriteEngine on 

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 

#First rewrite any request to the wrong domain to use the correct one (here www.) 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

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

RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html) 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L] 
</IfModule> 

我怎樣才能不https://cdn.domain.com任何affectting改變主域設置?

+2

www是你應該再添'的RewriteCond%{HTTP_HOST第二塊加}!cdn.domain.com'在那裏。你可以在這裏測試它[http://htaccess.mwl.be/](http://htaccess.mwl.be/) –

回答

2

我認爲你正在尋找這樣的:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] 

你的htaccess看起來現在這個樣子:

<IfModule mod_rewrite.c> 
RewriteEngine on 

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 

#First rewrite any request to the wrong domain to use the correct one (here www.) 
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] 

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

RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html) 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L] 
</IfModule> 
+1

小心解釋downvotes? –