繁体   English   中英

mod_rewrite,如何正确重写链接

[英]mod_rewrite, how to rewrite links correctly

我正在尝试重写我网站上的链接。 重写之前可能的链接以及重写之后我想看到的内容:
/index.pl?mode=users&action=add /users/add/
/index.pl?mode=streets&action=edit&id=7 /streets/edit/7
/index.pl?mode=users&action=info&id=7 /users/info/7
等等

.htaccess内容:

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule ^([A-Za-z0-9-]+)/((edit|delete|info))/([0-9]+)$ index.pl?mode=$1&action=$2&id=$3 [L]
RewriteRule ^([A-Za-z0-9-]+)/((add))/?$ index.pl?mode=$1&action=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.pl?mode=$1 [L] 

/users/add//street/add/正常运行,但是...

问题:
/users/edit/xx我无法在perl脚本中接受ID。 为什么?
/users/info/xx我什至无法进入信息部分/?mode=users&action=info&id=7页面(它必须显示具有错误ID的空白表格

顺便说一句...我的网站具有“开关”结构。 我的意思是,如果mode是users,则加载“ users.pl”,如果mode = streets加载“ streets.pl”,等等。关于第二个问题-确保我在users.pl上有信息部分! 链接/?mode=users&action=info&id=7可以完美工作。

ps:添加了php-tag,因为它不是'perl'问题,但是php等于perl,所以php-followers也可以帮助我
pps:对不起,我的英语不好。

您有太多的括号,这会使您的反向引用一一对应:

RewriteRule ^([A-Za-z0-9-]+)/(edit|delete|info)/([0-9]+)$ index.pl?mode=$1&action=$2&id=$3 [L]
RewriteRule ^([A-Za-z0-9-]+)/(add)/?$ index.pl?mode=$1&action=$2 [L]

这两个规则在((edit|delete|info))((add))周围有太多括号(尽管“ add”不受影响,因为$ 2正确地反向引用了它)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM