【发布时间】:2012-12-05 13:10:43
【问题描述】:
我正在尝试重写 URL 中的破折号,以便它们在内部不存在。例如这个网址
localhost/mysite/关于我
“about-me” 应重写为 “aboutme”。我需要这个,因为控制器类名取决于这个路由字符串,我显然不能为此使用破折号。
这是我发现的条件和规则,我认为应该符合我的需要:
# Condition is to avoid rewrite on files within specified subdirs
RewriteCond $1 !^(css|img|ckeditor|scripts)
RewriteRule ^([^-]+)-([^-]+)$ $1$2 [L]
但它似乎不起作用,因为控制器类 Aboutme 没有实例化。相反,我得到了 404 错误,而且我对名称中没有破折号的类似控制器类没有任何问题。
你能帮我解决这个问题吗?
【问题讨论】:
-
好吧,入口文件路径是 localhost/mysite/index.php,但我已经在另一对条件规则中处理了这个:RewriteCond $1 !^ (index.php|css|img|scripts|ckeditor|robots.txt|sitemap.xml|sitemap.xml.gz) RewriteRule ^(.*)$ index.php/$1 [L]
-
-是一个正则表达式条件,如果我没记错的话,你试过\- -
我也尝试使用
^([^\-]+)\-([^\-]+)$和^([^\-]+)-([^\-]+)$转义破折号,但问题仍然存在。
标签: php apache codeigniter mod-rewrite rewrite