问题
How can i catch the prams after file name with extension like service.php/view1
for ex:
service.php/newview1
I want to get it like service.php?view=newview1
how do i write mod-rewrite for this
I tried like
RewriteRule ^services.php/?([a-zA-Z_]+)$ /services.php?category=$1
its not matching the service.php/newview1
回答1:
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
You need to add [QSA]
flag to end of your current line
Try adding this regex:
([a-zA-Z0-9-_]+)
as this also matches any integers and hyphens also.
RewriteRule ^services.php/?([a-zA-Z0-9-_]+)$ /services.php?category=$1 [QSA,L]
I also put the [L]
flag so it stop processing further rules.
来源:https://stackoverflow.com/questions/22143744/apache-mod-rewrite-htaccess-to-get-params