How to hide params passed in url using .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?ur开发者_运维百科l=" part in the url. is this possible? please suggest.
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>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/(.*)/$ /page.php?url=$1 [L]
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]
精彩评论