• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to redirect everything from www to nonwww except for few files?

A

account8226

Guest
#1
Hey, I wanted to use the redirection where all my link www.site.com are redirected to site.com !

BUT, the problem is that I want to keep the www.site.com AND the www.site.com/sitemap.xml, I don't want these two links to be redirected because there will be problems.

Thanks you very much for ur awnseres, sorry for my English I'm French !
 

Slavik

XenForo moderator
Staff member
#3
Code:
RewriteEngine on
RewriteRule ^(sitemap.xml)($|/) - [L]
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
 

Slavik

XenForo moderator
Staff member
#9
Any idea ? Sorry to annoy you :(
How many subfolders and files are in your root?

With the code

Code:
RewriteEngine on
RewriteRule ^(index.php)($|/) - [L]
RewriteRule ^(sitemap.xml)($|/) - [L]
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
All URLs apart from www.domain.com/index.php and www.domain.com/sitemap.xml will be redirected to their non-www counterparts. The problem is there is no real way to put a rule in to stop just www.domain.com/ (with no index.php) from staying there.

If you don't have too many folders and files, you could simply write rules for all of them manually.
 
A

account8226

Guest
#10
Thanks for the awnsers. It worked :) For the main domain I think I found a solution to generate my sitemap with domain.com :) Tx again!