Rewriting URIs with parameters using .htaccess
hi i need to know how htaccess file should be modified according to the below scenario.
convert this localhost/site1/viewUser?selectedSearchedUsername=user1
to something like this localhost/site1/viewUser/user1
I currently use below code snippet in htacces开发者_开发技巧s for hide php extension and it works fine.but still no luck in hiding get variables in url as above scenario
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
thanx..
To convert this HTTP request from
http://localhost/site1/viewUser?selectedSearchedUsername=user1
to
http://localhost/site1/viewUser/user1
You can simply use
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/site1/viewUser/(.*) /site/viewUser?selectedSearchedUsername=$1 [L]
The [L]
is here to indicate that this is the last rule. You might be careful and want to be more restrictive in what you are allowing to match. For example if the username is only a sequence of ascii letters and numbers you can catch that, or you can sanitize letter in your program. Just be careful to not leave the door open.
精彩评论