Home mod_rewrite rule to capture query parameters if present
Reply: 1

mod_rewrite rule to capture query parameters if present

Alex
1#
Alex Published in 2018-01-12 13:42:30Z

I have the following rules in my htaccess file:

RewriteRule ^/(v[0-9]+)/(resource)/?$ /$1/file.php?resource=$2 [NC,L]
RewriteRule ^/(v[0-9]+)/(resource)/([A-z0-9_]+)/?$ /$1/file.php?resource=$2&resource_id=$3 [NC,L]

This rewrites URLs like

/v1/resource/ to /v1/file.php?resource=resource

and

/v1/resource/resource_id to /v1/file.php?resource=resource&resource_id=resource_id

How can I write a rule that takes in consideration a query parameter in the “beautified” URL? E.g.

/v1/resource/?filter=filter_val to /v1/file.php?resource=resource&filter=filter_val
MarcusKreusch
2#
MarcusKreusch Reply to 2018-01-12 13:49:10Z

You want to add "QSA" (="query string append") in the square brackets:

RewriteRule ^/(v[0-9]+)/(resource)/?$ /$1/file.php?resource=$2 [NC,L,QSA]

You may read this for further reference: Apache Doc

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.566234 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO