Re-write index.php to /home/ using htaccess

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjayis
    New Member
    • Mar 2008
    • 134

    Re-write index.php to /home/ using htaccess

    Hi

    i m using htaccess to rewrite my urls.,

    In this instead of http://www.mysite.com/index.php i want the url as http://www.mysite.com/home/

    any ideas??

    and also i m using the following code to redirect to the http://www.mysite.com/index.php when a non-existing filename is typed..

    Code:
    .........
    .............
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_URI} !^/Admin 
    RewriteRule ^ http://www.mysite.com/index.php
    so i want the url to be displayed as http://www.mysite.com/home/ whenever http://www.mysite.com/index.php is called..And at the same time when an non-existing filename i,e url is passed it must be redirected to http://www.mysite.com/home/ instead of http://www.mysite.com/index.php


    regards
    vijay
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You should simply look for "index.php" and redirect it to "/home/".
    Using the [R] option will cause a redirect, which will cause the URL to change in the user's browser.

    That should be as simple as:
    Code:
    RewriteRule ^index\.php$ /home/ [R]

    Comment

    • vjayis
      New Member
      • Mar 2008
      • 134

      #3
      Originally posted by Atli
      Hi.

      You should simply look for "index.php" and redirect it to "/home/".
      Using the [R] option will cause a redirect, which will cause the URL to change in the user's browser.

      That should be as simple as:
      Code:
      RewriteRule ^index\.php$ /home/ [R]


      Hi

      tried by placing it but page results by displaying the error message as

      ""
      This webpage has a redirect loop.

      The webpage at http://www.mysite.com/home/ has resulted in too many redirects
      ""

      i think it may be due to the rewirte rule i hav placed for the non existing file or urls

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Yea, that last rule in your code doesn't look quite right.
        If I put that into the .htaccess file on a project I'm working on now I also get the "to many redirects" error.

        Try removing that, see what happens.

        Comment

        • vjayis
          New Member
          • Mar 2008
          • 134

          #5
          tried and it also results in an error which says that

          "
          Oops! This link appears broken.
          HTTP 404 - File not found.

          "

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Ok.

            That may cause a problem, because re-directing back and forth like that ends up causing an indefinite loop.

            There is a far easier solution, if you want.

            Because index.php is an index file, if you simply specify the directory that contains the file, it will be executed.
            In your case, that is the root directory.

            So rather than showing example.com/home/ it would just show example.com/.
            Code:
            RewriteRule ^index\.php$ / [R]
            That way, you don't need to redirect the /home/ directory back to the index file and enter a loop. The index file would be automatically executed.

            And if you want all non-existing files to go there as well, you could catch the 404 error and show the the index file, which would be re-directed like a normal link:
            Code:
            ErrorDocument 404 /index.php

            Comment

            • vjayis
              New Member
              • Mar 2008
              • 134

              #7
              Hi

              thanks for ur help., and it works good.,

              but the rewrite rules written for index.php gets changed., and no probs i can get rid of it..

              but i need it to be displayed as http://www.mysite.com/home/ instead of http://www.mysite.com/

              anyother way ???

              Comment

              Working...