.htAccess Assistance for links

Discussion in 'Apache' started by Deepak Kumar Vasudevan, Mar 16, 2013.

  1. #1
    In my personal website at http://www.lavanyadeepak.tk/, I have the top like 'index.php?pg=profile', 'index.php?pg=home' or 'index.php' (without any querystring), 'index.php?pg=diary' etc.

    I am looking to see if I can have .htaccess file which can make me create links like

    index.php/
    index.php
    index.php/home
    index.php/profile
    index.php/diary

    Is this possible? Can some one help me write an .htaccess for the same please?
     
    Deepak Kumar Vasudevan, Mar 16, 2013 IP
  2. Techs@BC

    Techs@BC Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    31
    #2
    Hi Deepak,

    The solution here could help you: http://www.9lessons.info/2009/11/pretty-urls-with-htaccess-file.html

    Basically you will need to make all the links in your site to the way you want it. Eg: http://www.lavanyadeepak.tk/profile

    Then you can put redirect rules in your .htaccess like below:


    <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?pg=$1

    </IfModule>
    The RewriteCond lines make sure the re_write rules do not mess with any files names your site might have. The RewriteRule line takes all characters from starting (^) to end ($) after your domain name, and pass it on to variable $1. The "/?" makes sure that any trailing "/" are also accommodated for in the query.
    Of course, you will need to test this thoroughly for your environment and make necessary modifications before using it in live site.
    Good Luck!
     
    Techs@BC, Mar 19, 2013 IP