domain.com to www.domain.com redirect

Discussion in 'Apache' started by popoman, Jun 20, 2006.

  1. #1
    domain.com to www.domain.com redirect

    Can somebody just give me the simple .htaccess code of this kind of redirect?

    And also, can I redirect a subdomain to a domain this way, how will it look inside of the .htaccess?

    Thanks.
     
    popoman, Jun 20, 2006 IP
  2. Leo727

    Leo727 Active Member

    Messages:
    161
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I always use the following, it works well :

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

    I'm not certain, but you can probably use the same for subdomains, just put the full subdomain in the first line.
     
    Leo727, Jun 20, 2006 IP
  3. popoman

    popoman Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks,

    But if I want to put 2 codes in the .htaccess, do I do it one after the other like that:

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

    RewriteCond %{HTTP_HOST} ^SUBDOMAIN.YOURDOMAIN\.com [NC]
    RewriteRule ^(.*)$ http://www.YOURDOMAIN.com/$1 [L,R=301]
     
    popoman, Jun 20, 2006 IP
  4. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #4
    Put this exactly to .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
    RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
    </IfModule>
     
    iatbm, Jun 20, 2006 IP
    droper likes this.
  5. popoman

    popoman Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm sorry to annoy, but...

    This is the subdomain:
    RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]

    And this is the one I want it go to:
    RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]

    Right?

    And is this a permanent redirect? Will the backlinks to my subdomain now point to my domain?

    Thanks.
     
    popoman, Jun 20, 2006 IP
  6. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #6
    301 ... permanent yes :D

    I am using this on all sites without any problem ... just try and type istoritve.com ... and you will see that it redirects you to www.istoritve.com !
     
    iatbm, Jun 20, 2006 IP
  7. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #7
    301 ... permanent yes :D

    I am using this on all sites without any problem ... just try and type istoritve.com ... and you will see that it redirects you to www.istoritve.com !
     
    iatbm, Jun 20, 2006 IP
  8. popoman

    popoman Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, thank you.
     
    popoman, Jun 20, 2006 IP
  9. TwisterMc

    TwisterMc Mac Guru

    Messages:
    972
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    TwisterMc, Jun 28, 2006 IP
  10. damier

    damier Active Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #10
    I'm using

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^domain\.com
    RewriteRule (.*) http://domain.com/$1 [L,R=301]
    
    Code (markup):
    To redirect hxxp://www to hxxp:// this is affecting the way subdomains react on the server redirecting them to hxxp://domain.com/subdomain

    Is there a way to fix this so it ignores subdomains?
     
    damier, Jul 5, 2006 IP
  11. estis

    estis Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hello :) ,

    I need some help to configure my webserver, sorry for my english..

    I would like to redirect http://samedomain.be -> http://www.samedomain.be.

    I have apache2 and use http.conf to configure the url rewriting.

    Here's the http.conf file's :

    <VirtualHost 172.16.51.11:80>
    ServerName www.samedomain.be
    ServerAlias samedomain.be
    DocumentRoot /srv/www/htdocs

    <Directory /srv/www/htdocs>
    Allowoverride none
    Order allow,deny
    Allow from all
    </Directory>

    ExtFilterDefine uncomment mode=output cmd=/srv/www/htdocs/htmclean

    <Files *.php>
    ExtFilterOptions DebugLevel=0
    SetOutputFilter uncomment
    </Files>

    <Files Details>
    ForceType application/x-httpd-php
    </Files>
    <Files Recherche>
    ForceType application/x-httpd-php
    </Files>
    <Files Commandes>
    ForceType application/x-httpd-php
    </Files>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.samedomain\.be [NC]
    RewriteRule ^(.*) http://www.samedomain.be/$1 [L,R=301]
    </IfModule>

    </VirtualHost>



    What's the problem ? > the url rewriting don't work !

    I imagine that the rewrite module is not load.
    In the sysconfig directory/loadmodules.conf, the LoadModule rewriteModule don't exist, if add to load the module and restart apache, the new line is delete.

    I don't undetstand why it make me not happy, need help

    Thanks

    Steve
     
    estis, Jul 24, 2006 IP
  12. TwisterMc

    TwisterMc Mac Guru

    Messages:
    972
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Steve it looks like you are doing it the hard way. Don't use http.conf use the .htaccess file and add this code:

    RewriteCond %{HTTP_HOST} ^samedomain\.be [NC]
    RewriteRule ^(.*)$ http://www.samedomain.be/$1 [L,R=301]
     
    TwisterMc, Aug 9, 2006 IP
    hans likes this.