1. 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?

Discussion in 'Server Configuration and Hosting' started by account8226, Sep 4, 2011.

  1. account8226

    account8226 Guest

    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 !
     
  2. account8226

    account8226 Guest

    Anyone ?
     
  3. Slavik

    Slavik XenForo Moderator Staff Member

    Code:
    RewriteEngine on
    RewriteRule ^(sitemap.xml)($|/) - [L]
    RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
    
     
    Elly likes this.
  4. account8226

    account8226 Guest

    That's perfect but the main page www.domain.com is still redirected to domain.com ...
     
  5. Slavik

    Slavik XenForo Moderator Staff Member

    Just add another line

    RewriteRule ^(index.php)($|/) - [L]
     
    Elly likes this.
  6. account8226

    account8226 Guest

    Thanks for the awnser. But it's still redirecting to domain.com :(
     
  7. account8226

    account8226 Guest

    Any idea ? Sorry to annoy you :(
     
  8. Slavik

    Slavik XenForo Moderator Staff Member

    Am at poker. Will have a look when I get back in an hour or so.
     
  9. Slavik

    Slavik XenForo Moderator Staff Member

    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.
     
    Elly likes this.
  10. account8226

    account8226 Guest

    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!
     

Share This Page