Denis Šišić
Denis Šišić

Reputation: 47

RewriteRule slash optional

When I put "?" after slash to make it optional, like this:

RewriteRule ^user/(.*)/?$     "/index.php?page=view-user&user=$1"

But now when I open URL with slash like /user/revolution/ in PHP, $_GET['user'] output "rloveution/" (with slash). So how can I make the trailing slash optional without getting username output with slash ?

Thanks.

Upvotes: 2

Views: 109

Answers (1)

anubhava
anubhava

Reputation: 785631

You can use negated regex:

RewriteRule ^user/([^/]+)/?$ index.php?page=view-user&user=$1 [L,QSA]

Or lazy matching:

RewriteRule ^user/(.+?)/?$ index.php?page=view-user&user=$1 [L,QSA]

Upvotes: 1

Related Questions