repalcing php extensions with directories

Hi folks i been doing research but either im not searching for the right thing and or not getting what people are trying to explain.

basically i have an url as follows

http://www.mysite.com/index.php?page=directory1/page

what im trying to do is remove the “index.php?page=” so i get a

http://www.mysite.com/directory1/page

but im not too sure how to go about that some places say use .htaccess others suggest php preg replace but truly im not sure where to begin

any tutorials or links or help is welcomes

thanks in advance!

Create an .htaccess text file in your root directory.

Type this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [PT,L]

When you this on your address bar:
http://www.mysite.com/directory1/page

the directory1/page will be passed to the “index.php?page=”.
like this one:
http://www.mysite.com/index.php?page=directory1/page”.
but without the “index.php?page=”.

after that, you can use $_GET[‘page’] for navigation.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service