htaccess-rewrite-rule for more than one parameter

落花浮王杯 提交于 2019-12-13 16:15:08

问题


I use the following rule

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

for rewriting

www.mysite.com/123

to

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

to

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

How can I achieve this? Thanks!


回答1:


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]


来源:https://stackoverflow.com/questions/16753370/htaccess-rewrite-rule-for-more-than-one-parameter

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