Grow your CSS skills. Land your dream job.

Redirect index.php request to http://localhost/website/ using .htaccess

  • # April 3, 2013 at 12:53 am

    I’m not so familiar with configuring my .htaccess yet so please help me out.

    I have a link that goes to the index.php but I don’t want index.php to appear in my url

    eg.
    http://localhost/website/index.php

    I want it to be redirected to the root folder which is

    http://localhost/website/

    So i tried searching for answers and this is what I got so far.

    RewriteEngine on

    Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ http://localhost/website/$1 [R=301,L]

    Now when I try to click home in my local website, instead of redirecting me to

    http://localhost/website

    my url bar displays this -

    http://localhost/Applications/XAMPP/xamppfiles/htdocs/website/localhost/website/

    Can anyone explain what’s going on?

    # April 3, 2013 at 2:28 am

    > I have a link that goes to the index.php but I don’t want index.php to appear in my url

    THIS is the part you don’t understand. If you don’t want the link to show `…index.php` in the address bar, then change the link, not your server. In and of itself, this has absolutely nothing to do with mod_rewrite.

    Take this

    my link

    …and replace it with this

    my link

    In most cases, you won’t need to do anything more – when given a path to a directory, Apache is typically already configured to look for a file named `index.php` (among others) and serve it if found.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".