views:

7

answers:

1

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 ^user/(.*) 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?

+1  A: 

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]
Gumbo
Does it really matter if the site has a mix of both?
Keverw
@Keverw: No, you can use whatever URLs you want. But I would just use a consistent scheme.
Gumbo
Okay. Thank You for your help!
Keverw