Forum Moderators: phranque

Message Too Old, No Replies

redirect home.php to index.php

quick help about rewrite rule

         

phparion

5:47 am on May 13, 2007 (gmt 0)

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



RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^.*home\.php$ [NC]
RewriteRule ^ index.php [R,L]

from above i want to redirect mydomain.com/home.php to index.php

but it give me 404 page not found error like the htaccess doesnt work at all..

can anybody help please

phparion

6:08 am on May 13, 2007 (gmt 0)

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



RewriteEngine On
RewriteBase /

RewriteRule ^home\.php$ index.php [L]

this one also doesnt work

jdMorgan

2:22 pm on May 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You second attempt is correct, but it is an internal rewrite. For an external redirect, modify it like this:

RewriteRule ^home\.php$ [b]http://www.example.com[/b]/index.php [[b]R=301,[/b]L]

If you still have problems, we need to know:

Where is this code installed? -- What directory?

What is the name of the "home page" file accessed when "example.com/" is requested from your server (as defined by by the DirectoryIndex directive)?

Jim

phparion

5:31 pm on May 13, 2007 (gmt 0)

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



:(( still not working,

I am in the root directory, i do have a home.php page in the root so index.php, but htaccess doesn't match the /home.php to redirect it to the index.php.. index.php is the directory index

jdMorgan

7:15 pm on May 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put this in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^home\.foo$ http://www.example.com/index.php [R=301,L]

Now request "example.com/home.foo" from your server. If this doesn't work, there's a good chance that your server is not configured to allow you to use mod_rewrite -- Try using Redirect or RedirectMatch from mod_alias [httpd.apache.org] instead.

However, if this code does work with a ".foo" file extension, but does not work with a .php extension, then it is likely that one of several other things is causing a problem:

  • You may have other rewrite rules in .htaccess or httpd.conf that are interefering.
  • You may have "AcceptPathInfo on" or MultiViews enabled, which can also interfere.
  • Your PHP may be installed incorrectly, so that it runs before mod_rewrite can run. This can be a problem with Apache 1.x servers, where the module execution order is the reverse of the module load order -- As a result, more than a few hosting companies mis-configure this.

    Jim

  • g1smd

    1:05 am on May 15, 2007 (gmt 0)

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



    It is not usual to redirect from one named index page to another different named index page.

    Usually, redirect all named indexed pages to a trailing-slash URL that omits the actual index file filename.