Forum Moderators: phranque

Message Too Old, No Replies

example.com to example.com/index.php

htaccess redirect

         

rajnvr

2:05 am on Apr 11, 2012 (gmt 0)

10+ Year Member



hi WM-

i have already rectified the canonical url on my site. i have another challenge seems to be simple but i couldnt figure it out.

for an instance.

all example.com is redirected to www.example.com/index.php at present but
www.example.com is not redirected to www.example.com/index.php.

how to add the redirect rule. here is the my .htaccess rule

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php [L,R=301]

need your solution please

regards,
Raja

lucy24

9:07 am on Apr 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Awk! You are doing the exact opposite of what you need to do!

Pretend that the name "index.php" (or index.html or equivalent) simply does not exist. The name of an index file is the name of the folder it lives in.

example.com/ >> www.example.com/ if you prefer the with-www form. But www.example.com/ is already where you want it to be.

If "index.php" is not in your config file's list of Approved Index Names, that's a completely different question. You don't solve it by forcibly redirecting. You add a line to the config file or to htaccess, whichever one you're working in. Look up "DirectoryIndex" under mod_dir [httpd.apache.org]. It really is just one line.

g1smd

5:32 pm on Apr 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, redirect requests for index.php, index.html etc to URL ending with a trailing slash.

Place this set of rules before your non-canonical www/non-www ruleset to be sure that you avoid a multiple step redirection chain.