Apache mod rewrite .htaccess to get params

大憨熊 提交于 2020-01-07 05:35:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!