【问题标题】:Htaccess multilanguage mod_rewriteHtaccess 多语言 mod_rewrite
【发布时间】: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


    【解决方案1】:

    试试看:

    RewriteCond $1 ^[^/]*/?(gallery|post|products)
    

    【讨论】:

    • 感谢您的帮助,与此同时,我设法以某种方式使其与 Codeigniter 路由一起使用。我试过你的代码,它确实部分工作,语言 id 仍然给我带来问题。我已经决定 CI 路由已经足够好了......现在:)。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多