【发布时间】:2012-12-10 12:08:05
【问题描述】:
好的,我已经浪费了很多时间来解决这个问题,但是我越是尝试了解重写规则,我似乎就越不了解发生了什么。我需要为基于 codeigniter 的项目修复一些重写规则。
该应用程序是一个多语言 CMS,它基本上适用于模块、页面和帖子,在 .htaccess 文件中我需要检查 url 是页面还是帖子并重定向到适当的控制器。
到目前为止,在我的 .htaccess 文件中,我有以下内容:
#if I'm on the homepage and i have a language id
RewriteCond $1 ^([a-z]{2})/?$
RewriteRule ^(.*)$ index.php?homepage/index/$1 [PT,L]
#if module - this works ok when there is no language id
RewriteCond $1 ^(gallery|post|products)
RewriteRule ^(.*)$ index.php?$1 [PT,L]
# Rewrite all other URLs to index.php/URL - page controller
RewriteRule ^(.*)$ index.php?page/show/$0 [PT,L]
上面的代码,如果我输入了
http://mydomain.com/gallery/something/9
一切都很好,花花公子,如果我像这样添加语言 ID:
http://mydomain.com/en/gallery/something/9
它不再工作了,我从页面控制器收到一个找不到页面/404 错误(在 .htaccess 末尾重定向)。
假设我的网址看起来像这样:
http://mydomain.com/gallery/something/9
http://mydomain.com/en/gallery/something/25
http://mydomain.com/fr/post/something/31
我需要以某种方式将这些网址重定向到
http://mydomain.com/gallery/something/9
http://mydomain.com/en/gallery/somethingelse/25
http://mydomain.com/fr/post/somethingelse/31
请注意,有时我有语言 ID,有时没有。 这是我应该使用 htaccess 做的事情吗? Codeigniter 路由是更好的选择吗? 感谢您对堆栈溢出的任何帮助:)
【问题讨论】:
标签: apache .htaccess codeigniter mod-rewrite redirect