htaccess的重写规则为多个参数 [英] htaccess-rewrite-rule for more than one parameter

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

问题描述

我用下面的规则

RewriteRule ^([\w]+)/?([\w]+)? index.php?action=$1

重写

www.mysite.com/123

www.mysite.com/123

www.mysite.com/index.php?action=123

www.mysite.com/index.php?action=123

这需要保持这样的,但也有情况下,我还需要重写

This needs to remain like this, but there are cases where I also need to rewrite

www.mysite.com/123/abc

www.mysite.com/123/abc

www.mysite.com/index.php?action=123&example=abc

www.mysite.com/index.php?action=123&example=abc

我怎样才能做到这一点?谢谢!

How can I achieve this? Thanks!

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&example=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php?action=$1 [L,QSA]

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

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