1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Redirect non www and index.php to www.domain.com

Discussion in 'Apache' started by MrBounce, May 29, 2011.

  1. #1
    MrBounce, May 29, 2011 IP
  2. dynashox

    dynashox Premium Member Staff

    Messages:
    8,662
    Likes Received:
    563
    Best Answers:
    3
    Trophy Points:
    335
    #2
    To redirect index.php, try this:

    RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.domain.com$
    RewriteRule ^index\.php$ "http\:\/\/www\.domain\.com" [R=301,L]
     
    dynashox, May 29, 2011 IP
  3. MrBounce

    MrBounce Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    MrBounce, May 29, 2011 IP
  4. dynashox

    dynashox Premium Member Staff

    Messages:
    8,662
    Likes Received:
    563
    Best Answers:
    3
    Trophy Points:
    335
    #4
    dynashox, May 29, 2011 IP
  5. MrBounce

    MrBounce Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    So is it not possible to do that and also redirect domain.com to www.domain.com?

    I tried adding a simple:

    redirect 301 /index.php http://www.domain.com.au/

    But it caused an error/loop or something and the page failed to load.
     
    MrBounce, May 29, 2011 IP
  6. dynashox

    dynashox Premium Member Staff

    Messages:
    8,662
    Likes Received:
    563
    Best Answers:
    3
    Trophy Points:
    335
    #6
    Can you paste your .htaccess code here.
     
    dynashox, May 29, 2011 IP
  7. MrBounce

    MrBounce Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

    Is what is in there right now. That deals with domain.com to www.domain.com just fine, but does not deal with index.php

    The one you posted works awesome to redirect index.php but does not do what the above does.
     
    MrBounce, May 29, 2011 IP
  8. dynashox

    dynashox Premium Member Staff

    Messages:
    8,662
    Likes Received:
    563
    Best Answers:
    3
    Trophy Points:
    335
    #8
    You must combine both yours and my code together.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.domain.com$
    RewriteRule ^index\.php$ "http\:\/\/www\.domain\.com" [R=301,L]
     
    dynashox, May 29, 2011 IP
    MrBounce likes this.
  9. MrBounce

    MrBounce Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #9
    awesome, thanks so much.
     
    MrBounce, May 29, 2011 IP
  10. santhosh-LB

    santhosh-LB Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    save it as .htaccess
     
    santhosh-LB, May 30, 2011 IP