Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

with and without trailing slash

What would I make this rule so that you can access it with and without trailing slash?

RewriteRule ^members/([^/]+)$ members.php?id=$1 [L]
like image 896
Makan Avatar asked Jun 06 '26 05:06

Makan


2 Answers

RewriteRule ^members/([^/]+)/?$ members.php?id=$1 [L]

Just added "/?" at the end to say look for a trailing slash but the ? says it doesn't have to be there.

like image 109
nortron Avatar answered Jun 08 '26 00:06

nortron


I don't know anything about this "mod-rewrite" you speak of (probably an Apache module?), but that sure looks like a regex, and I know about those. :-)

Try this:

RewriteRule ^members/([^/]+)(/|)$ members.php?id=$1 [L]

So, to break that into pieces, the ^ means "begins with", "members/" means matching exactly that, ([^/]+) means "1 or more characters that aren't slash, assigning to $1", (/|) means "slash or empty string, assigning to $2", and the $ part at the end means "the string has to end here".

like image 28
asveikau Avatar answered Jun 07 '26 23:06

asveikau