Forum Moderators: phranque

Message Too Old, No Replies

htaccess /index.php redirect

Existing RewriteRule

         

leungd

1:16 pm on Jul 8, 2010 (gmt 0)

10+ Year Member



Hi,

Would appreciate any help from those with more experience.

I'm helping my friend out with his site (calling it
site.com
) and I noticed that his homepage is being redirected as
http://www.site.com/index.php
. I want to 301 redirect this to just
http://www.site.com
, however, I read that there's a possibility of creating an infinite loop if I just go ahead and do a 301 redirect (site.com/index.php redirecting to site.com, which calls site.com/index.php, which redirects, etc...)

I read online that I can do a non-infinite-loop redirect using the htaccess file, along with creating a 'dummy file' (calling it sitehome.php) and copying the contents of my index.php to sitehome.php.

I'm supposed to then add this into the htaccess file,

DirectoryIndex sitehome.php


while deleting everything in my original index.php file and putting in this line:

<? header("Location: http://www.example.com"); ?>


However...

I took a look at the existing htaccess file but I'm not quite sure I understand what's going on because it looks like:

AddDefaultCharset UTF-8
# BEGIN Mod_Rewrite
RewriteEngine On
RewriteCond %{http_host} ^site.com
RewriteRule ^(.*) http://www.site.com/$1 [R=301,L]
# END Mod_RewriteRewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.site\.com\/index\.php" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^info/index.html$ "http\:\/\/www\.site\.com\/index\.php" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^referral/?$ "http\:\/\/www\.site\.com\/index\.php" [R=301,L]


I think I understand the first Rewrite is adding 'www' to the URL of the site if a user hasn't specified it

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


But I don't understand the next 3 Rewrite's and it looks like I could mess something up if I followed the 301 redirect solution above (the one with the dummy sitehome.php file), since there are existing redirects/rewrites specifically for index.php

My main question is: should I go ahead and try the non-infinite-loop redirect solution, using the dummy file sitehome.php, and corresponding DirectoryIndex command in the htaccess without seriously messing up the site?

Thanks for your help!

Best,
-Duncan

leungd

3:41 pm on Jul 8, 2010 (gmt 0)

10+ Year Member



I decided to just run with the sitehome.php method (with backups of course), and I ended up with the following message (but unfortunately still with the URL:
http://www.1on1mandarin.com/index.php
)

Warning: Cannot modify header information - headers already sent by (output started at /home/jon1m0/public_html/index.php:1) in /home/jon1m0/public_html/index.php on line 1


I'm actually not sure what the above error means, and how to fix it.

On another note; I did take a look at previous posts on this forum regarding index.php and sample code for the htaccess file to work around the infinite loop redirects, but I still get infinite loops.

Would appreciate any help regarding this. Thanks!