.htaccess profile rewrite help
RewriteRule ^user/(.*)/(.*) profile.php?user=$1&v=$2 [L]
works for http://10.0.1.5/user/Kevin/wall/
if i do http://10.0.1.5/user/Kevin/wall it 404's. if i do http://10.0.1.5/user/Kevin/ it 404's if i do http://10.0.1.5/user/Kevin it 404's
I tired
RewriteRule ^开发者_如何学Pythonuser/(.*) profile.php?user=$1 [L]
RewriteRule ^user/(.*) profile.php?user=$1 [L]
RewriteRule ^user/(.*)/(.*)/ profile.php?user=$1&v=$2 [L]
RewriteRule ^user/(.*)/(.*) profile.php?user=$1&v=$2 [L]
But it didn't work like i wanted. I want it to work with all 4 possible urls. What should i do?
Use a more specific pattern than .*
like [^/]+
and use /?$
to make the trailing slash optional:
RewriteRule ^user/([^/]+)/?$ profile.php?user=$1 [L]
RewriteRule ^user/([^/]+)/([^/]+)/?$ profile.php?user=$1&v=$2 [L]
But as I recommend to just use one of the formats (with or without trailing slash), remove or add the trailing slash if it is present or missing:
# remove trailing slash
RewriteRule (.*)/$ /$1 [L,R=301]
# add trailing slash
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule .*[^/]$ /$0/ [L,R=301]
精彩评论