简体   繁体   中英

htaccess redirect www to non-www without changing in address

I have this address

http://name.com/category/1/news

I use this code in htaccess to force open page without www.

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

When I open http://www.name.com/category/1/news then I redirect to

http://name.com/category.php?id=1&slug=news

Here is my full htaccess file.

RewriteEngine on
RewriteRule ^news/(.*)$ news.php?id=$1&slug=$2
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Thanks.

Try :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [NE,R=301,L]
RewriteRule ^news/(.*)$ news.php?id=$1&slug=$2 [NC,L]

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