.htaccess and rewrites Rules

匆匆过客 提交于 2019-12-11 10:08:19

问题


I have some difficulties to create a simply htaccess for url rewriting.

What I would like is url with 3 parameters :

www.example.com => index.php

www.example.com/module/ => index.php?module=$1

www.example.com/module/action/ => index.php?module=$1&action=$2

www.example.com/module/action/1 => index.php?module=$1&action=$2&params=$3

I did that with many tutorials, but when I try with the last one, it's failed

RewriteRule ^web/([^/]*)$ index.php?module=$1 [L,QSA]
RewriteRule ^web/([^/]*)/(.*[^/])$ index.php?module=$1&action=$2 [L,QSA]
RewriteRule ^web/([^/]*)/(.*[^/])/([0-9]*)$ index.php?module=$1&action=$2&params=$3 [L,QSA]

Someone could help me ?

Thanks

Bouffe


回答1:


The .* part of your second expression is gobbling up anything after /action/ so you need to limit it the same as the one right before the / and use the + instead of *:

RewriteRule ^web/([^/]+)$ index.php?module=$1 [L,QSA]
RewriteRule ^web/([^/]+)/([^/]+)/?$ index.php?module=$1&action=$2 [L,QSA]
RewriteRule ^web/([^/]+)/([^/]+)/([0-9]+)/?$ index.php?module=$1&action=$2&params=$3 [L,QSA]


来源:https://stackoverflow.com/questions/20621565/htaccess-and-rewrites-rules

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