.htaccess并重写规则 [英] .htaccess and rewrites Rules

查看:288
本文介绍了.htaccess并重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建用于URL重写的简单htaccess时遇到一些困难.

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

我想要的是带有3个参数的网址:

What I would like is url with 3 parameters :

www.example.com => index.php

www.example.com => index.php

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

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

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

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

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]

有人可以帮助我吗?

谢谢

布菲

推荐答案

第二个表达式的.*部分吞噬了/action/之后的所有内容,因此您需要将其限制为与,然后使用+代替*:

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]

这篇关于.htaccess并重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆