开发者

Rewriting URIs with parameters using .htaccess

开发者 https://www.devze.com 2023-02-03 08:21 出处:网络
hi i need to know how htaccess file should be modified according to the below scenario. convert this localhost/site1/viewUser?selectedSearchedUsername=user1

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号