【问题标题】:Can we use CodeIgniter without htaccess file我们可以在没有 htaccess 文件的情况下使用 CodeIgniter
【发布时间】:2016-05-04 14:39:33
【问题描述】:

我是 CodeIgniter 的初学者,我的 .htaccess 文件遇到问题。是否需要在 CodeIgniter 中使用.htaccess 文件?

【问题讨论】:

  • 你可以……但我不推荐。
  • 我同意geggleto。只需研究如何构建一个好的 htaccess 文件。这是一个开始的地方:farinspace.com/codeigniter-htaccess-file
  • .htaccess 基本上是一个 webroot ini 覆盖。如果您可以控制您的服务器,则应考虑将其配置为不依赖 htaccess。谷歌搜索应该会为您指明正确的方向

标签: php .htaccess codeigniter


【解决方案1】:

可以,但如果您不使用像 nginx 这样的特殊网络服务器,则无法从 URL 中删除 index.php

如果你不会在 Apache Web 服务器上使用 .htaccess 文件,你的 URL 将如下所示(实际上你可以通过 httpd.conf 删除它,但不建议这样做):

http://www.yourdomain.com/index.php/your-url

如果你喜欢使用 nginx,你应该编辑nginx.conf 文件如下:

server {
        server_name domain.tld;

        root /your/codeigniter/folder;
        index index.html index.php;

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

        location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
        }

        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi.conf;
        }
}

您应该在nginx.conf 中的html {} 标记之间添加这件作品

如果您更喜欢 Apache + .htaccess 并想删除 index.php 东西,您应该创建一个 .htaccess 文件,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

请查看Codeigniter URL Guide 了解所有详情。我也同意@geggleto,.htaccess 文件不仅仅是 index.php 的东西,你可以用 htaccess 做很多事情。

【讨论】:

    猜你喜欢
    • 2021-08-09
    • 1970-01-01
    • 2012-03-18
    • 2017-04-05
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 2011-03-18
    相关资源
    最近更新 更多