Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RewriteRule Slash Single Redirect

I'm trying to create a new redirect for my v2.2 api.php file. The desired link is: website.com/api/v2.2/ but rewrite just works if I use _ instead of /:

website.com/api_v2.2/ (WORKS):

RewriteRule ^api_v2.2/?$ /api.php [NC,QSA,L]

website.com/api/v2.2/ (DON'T WORKS):

RewriteRule ^api/v2.2/?$ /api.php [NC,QSA,L]

Any idea? I've tried these lines too, but nothing works:

RewriteRule ^api\/v2.2/?$ /api.php [NC,QSA,L]

RewriteRule ^(api)/v2.2$ api.php [QSA,NC,L]
like image 740
Bruno Maciel Avatar asked Mar 19 '26 12:03

Bruno Maciel


1 Answers

Have you tried escaping the dot and slashes ?

RewriteRule ^api\/v2\.2\/?$ /api.php [NC,L]

The dot may cause problem here since it means "Any character" in the regex (source). Moreover, I don't think you need the QSA flag here.

like image 128
tchap Avatar answered Mar 22 '26 02:03

tchap