开发者

htaccess for dynamic username

开发者 https://www.devze.com 2023-01-25 01:17 出处:网络
Hi i\'m using this code for my subdirectories redirect for usernames RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d

Hi i'm using this code for my subdirectories redirect for usernames

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?username=$1&%{QUERY_STRING}

I have this problem that is user enter domain.com/username/ it will have problems, it only works if they enter domain.com/username

Any solutions to this??

Also, example if i have a real directory call /images/, when they enter domain.com/images. there开发者_StackOverflow中文版 will be an error regarding some looping problem. what is the way to solve this issue?


It's better to make your rewrites require the trailing slash.

then you can redirect non-slash ended urls to slash ended one,

using something like this :

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

I hope this helps.

0

精彩评论

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