Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide params passed in url using .htaccess

Tags:

.htaccess

I have a peculiar situation, my website is like

www.example.com/page.php?url=homepage
. I am trying to use .htaccess file to make url look like
www.example.com/page/homepage/

There by hiding the ".php?url=" part in the url. is this possible? please suggest.

like image 439
balanv Avatar asked Aug 01 '11 11:08

balanv


1 Answers

Try this:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /anything/anything -> anything.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_])/([^/]*)$ /$1.php?url=$2 [L]

</IfModule>

If the page.php filename will always be the same, then do it like this:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /page/anything -> page.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ /page.php?url=$1 [L]

</IfModule>
like image 160
Shef Avatar answered Sep 30 '22 20:09

Shef