【问题标题】:Restrict the url_suffix in codeigniter限制codeigniter中的url_suffix
【发布时间】:2014-02-16 20:20:07
【问题描述】:

我使用的是 codeigniter 2.1.4,我设置了$config['url_suffix'] = ".html";

它运行良好,没有任何问题。但我发现如果我使用redirect(); 函数,总是会在着陆页网址上添加url_suffix。例如:site.com/login/success.html

我的问题是在使用redirect() 函数时排除url_suffix 吗?或者无论如何添加.html而不在codeigniter中设置url_suffix,可能是.htaccess中的一些hack??

我尝试添加

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html

在项目 htaccess 文件中,但是一旦我取消设置 url_suffix 变量,框架就会抛出 404 错误。有什么解决办法吗?

谢谢:)

【问题讨论】:

    标签: php .htaccess codeigniter codeigniter-2


    【解决方案1】:

    您可以将url_suffix 配置留空$config['url_suffix'] = ''; 并定义特定路由以在某些情况下添加.html 后缀。

    例如,对于博客文章:

    routes.php(默认位于application/config/

    $route['blog/(.+)\.html'] = "posts/view_post/$1";
    /*                           ^     ^         ^
                                 |     |         |
                    Controller ---   Method      --- Post SEO url or ID
    */
    

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 2012-02-22
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 2011-08-21
      • 2017-04-06
      相关资源
      最近更新 更多