Reputation: 10898
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.
Upvotes: 8
Views: 16821
Reputation: 11
This code you can hide you page name
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ pagename.php?name=$1&id=$2 [NC,L]
Upvotes: 1
Reputation: 45589
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>
Upvotes: 12
Reputation:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/(.*)/$ /page.php?url=$1 [L]
Upvotes: 4