【问题标题】:Take the index.php out of Code Igniter URLs从 Code Igniter URL 中取出 index.php
【发布时间】:2011-01-20 23:49:27
【问题描述】:

我是 Code Igniter 的新手(就像我刚刚完成了他们的“官方”视频教程一样),我想知道是否有办法稍微清理一下 URL。

基本上,是否有一些设置可以将“index.php”排除在 URL 之外?

所以不是这个...

http://localhost/codeigniter/index.php/blog/comments/

...你看到了:

http://localhost/codeigniter/blog/comments/

还是我必须自己用 .htaccess 重写 URL?

【问题讨论】:

  • 不要使用 .htaccess。请改用 httpd.conf 并关闭覆盖。 ;)

标签: codeigniter codeigniter-url


【解决方案1】:

使用 .htaccess 更容易,我猜其他方式可能不适用于共享主机。 我猜是这样的:

<IfModule mod_rewrite.c>
    RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

【讨论】:

    【解决方案2】:

    请按照以下说明进行操作。

    http://codeigniter.com/wiki/mod_rewrite/

    只需 1 个 htaccess 文件和 1 个配置文件修改

    【讨论】:

      【解决方案3】:

      您没有“必须”使用 htaccess,但以任何其他方式执行此操作将是一大堆麻烦(想想在 php 中从 .../index.php/... 重定向到非 index.php版本)。

      任何值得他们盐分的 php 开发人员都会在 .htaccess 中完成。

      【讨论】:

        猜你喜欢
        • 2018-08-22
        • 2012-01-29
        • 2011-04-29
        • 2016-05-19
        • 1970-01-01
        • 2012-04-04
        • 1970-01-01
        • 2022-06-14
        • 1970-01-01
        相关资源
        最近更新 更多