htaccess problem

Discussion in 'PHP' started by TheGrinch, Nov 19, 2010.

  1. #1
    Hi

    My existing index page is index.html but I would like to create a 301 redirect so that when people either land on the root of the domain e.g. mydomain.com/ the automatically go to index.php.

    However, despite using the code below people are still going to index.html rather than index.php

    I would be very grateful if someone could help me out please - Thanks

    My .htaccess code at present looks like this

    RewriteEngine on
    RewriteRule ^/$ index.php [R=301,L]
    RewriteRule ^index\.html$ index.php [R=301,L]
     
    TheGrinch, Nov 19, 2010 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
  3. TheGrinch

    TheGrinch Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nope - none of those worked. I use apache so the 301 is different

    all of my 301 rewrites work except the one for the root directory
    i.e. / should automatically go to index.php
     
    TheGrinch, Nov 19, 2010 IP
  4. badhim

    badhim Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    Try this code:

    RewriteEngine on
    RewriteRule ^$ \/index.php [R=301,L]
    RewriteRule ^index\.html$ \/index.php [R=301,L]
     
    badhim, Nov 19, 2010 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    Might work...?

    
    
    Options +FollowSymLinks
    
    RewriteEngine on
    
    RewriteBase /
    
    RewriteRule ^index\.php index.html [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
    
    RewriteRule ^index\.html /index.php [R=301,L]
    
    
    Code (markup):
     
    MyVodaFone, Nov 19, 2010 IP
  6. TheGrinch

    TheGrinch Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks I'll check these out. I may have found an alternative reason as to why it is not working. The domain is hosted used Apache on an IIS server - so perhaps the default page just needs to be changed to index.php.... we shall see
     
    TheGrinch, Nov 19, 2010 IP
  7. graspit

    graspit Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    if index.html is the same as index.php, then you can delete the index.html file and users will be redirected automatically to index.php, no need to modify your .htaccess file.
     
    graspit, Nov 19, 2010 IP
  8. badhim

    badhim Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #8
    Anyway, if the index.html page is pretty old, it is a good idea to leave the redirection from index.html to index.php. Because some visitors may have bookmarked this page.
     
    badhim, Nov 19, 2010 IP