简体   繁体   中英

301 when www. infront of subdomain

Could anyone please explain the redirect conditions and rule to achieve this:

  1. User visits www.example.domain.com
  2. 301 to example.domain.com

(Basically removing the www. from the URL, but ONLY when they access a subdomain.

It must allow access at www.domain.com

Thanks!

Adding this to the htaccess file:

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

will redirect www.example.domain.com to http://example.domain.com it will even redirect www.other.domain.com to http://oter.domain.com

Try this,

 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^www\.([a-zA-Z0-9]+)\.domain\.com [NC]
 RewriteRule ^(.*)$ http://%1.domain.com/$1 [L,R=301]

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