简体   繁体   中英

.htaccess rule for removing www from url

Whenever someone hits

http://www.example/consumer-complaints

it should become

http://example.com/consumer-complaints

The copy&paste .htaccess rules do not seem to work for me. It removes www when someone hits

> http://www.example/consumer-complaints

but it redirects to only http://example.com

instead of

http://example.com/consumer-complaints

Can someone write an .htaccess rule for me

Thank you

The .htaccess Code:

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

Conversely, if you'd prefer to use "www" in all of your URLs, you can code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.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