Say example my domain is http://www.domain.com and i wanted to redirect into no-www url ( http://domain.com ), for that i used this code in .htaccess
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It's working fine http://www.domain.com redirects to http://domain.com .
Now i have a sub-domain http://www.blog.domain.com (public_html/blog) to be redirected into no-www url http://blog.domain.com for that i used this code.
RewriteCond %{HTTP_HOST} !^blog\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://blog.domain.com$1 [R=301,L]
But then also www is not removing in the sub-domain url. What i am doing wrong here?
Update: My hosting provider is hostgator
Step 1:
It seems there is a WP .htaccess inside /public_html/blog
also. Add this rule before WP rules in your /public_html/blog/.htaccess:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Step 2:
Then in WP permalink settings
change your blog address to:
http://blog.domain.com
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.