简体   繁体   中英

htaccess force www not for cdn

I have a problem with .htaccess forcing www.

I have the main site http://www.portalesardegna.com and I want to redirect http://portalesardegna.com to the www version, but I have even a CDN, http://cdn.portalesardegna.com , if I look the site with pingdom http://tools.pingdom.com /fpt/#!/eHy16D/www.portalesardegna.com all the files in the cdn are redirected to the www version.

Some information that can be useful:

  1. The CDN is on an external service, and the dns point to another server, not mine.
  2. I have some images from another subdomain in my site, private3.portalesardegna.com, and all of these images are not redirected.

Here is the code i use in the htaccess

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^cdn\..+$ [NC]
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Try this rule as as your very first rule in your root .htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(cdn|www)\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM