unclepete
unclepete

Reputation: 77

htaccess Detect slash AND no slash in directory

With:

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?pet=$1 [NC]

"www.domain.com/cat" works but "www.domain.com/cat/" doesn't (notice slash at the end).

How can I modify this rule to work with AND without the slash? Or do I need two rules?

Upvotes: 0

Views: 96

Answers (1)

anubhava
anubhava

Reputation: 785611

Just include an optional trailing slash in your regex:

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?pet=$1 [L,QSA]

You can also use:

RewriteRule ^([\w-]+)/?$ index.php?pet=$1 [L,QSA]

Upvotes: 1

Related Questions