【问题标题】:Codeigniter remove index.php on NginxCodeigniter 删除 Nginx 上的 index.php
【发布时间】:2016-07-05 22:39:54
【问题描述】:

我正在使用 Codeigniter 框架,我在共享主机上测试了网站,它与 .htaccess 一起工作正常。但是当我将它上传到具有 Nginx 的其他服务器时,我无法删除 index.php。我尝试了几乎所有 googel 的前两个页面,结果相同,但没有一个对我有用,我想从 URL 中删除 index.php。这是对我有用的 htaccess。

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

我想要 nginx.config 中这个 htaccess 的 corespond。 我不知道有什么问题。

【问题讨论】:

  • 你用谷歌搜索了它,那么当你使用first结果时会发生什么?
  • @Tpojka 什么都没有。所有没有 index.php 的链接。但在我手动添加 index.php 之前它们不起作用。
  • 修改后有没有尝试重启nginx?

标签: php .htaccess codeigniter nginx


【解决方案1】:

第一步:进入codeigniter文件夹,打开config.php文件并从$config['index_page'] = ''中删除“index.php”

第 2 步:在 codeigniter 文件夹中创建 .htaccess 文件并粘贴以下代码

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

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

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

<ifmodule mod_headers.c="">
  SetEnvIf Origin "^(.*\.YOUR_PROJECT_NAME)$" ORIGIN_SUB_DOMAIN=$1
  Header set Access-Control-Allow-Origin "*"
  Header set Access-Control-Allow-Methods: "*"
  Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, 
  Content-Type, Accept, Authorization"
</ifmodule>

第 3 步:查找

      $config['uri_protocol'] = "AUTO" 

替换为

      $config['uri_protocol'] = "REQUEST_URI"

也检查一下

      $config['enable_query_strings'] = FALSE;

第四步:重启xampp服务器并检查..

【讨论】:

    【解决方案2】:

    试试这个以获得更好的解决方案

    Step 1: Remove index.php from config.php. Open 
    /application/config/config.php 
    and remove index.php to “” ...
    Step 2: Edit htaccess file – For Apache Server. NOTE: This step is not for 
    nginx server users, Please check Step 2 for Nginx. ...
    Step 3: Edit nginx.conf file – For NGINX Server.
    

    【讨论】:

      【解决方案3】:

      这也让我发疯了。

      原来在 config.php 文件中玩这个有帮助。

      $config['uri_protocol'] = 'REQUEST_URI';
      

      我目前也在使用相同的 htaccess 规则

      【讨论】:

      • htaccess 在 Nginx 服务器上不起作用。我已经这样做了 $config['uri_protocol'] = 'REQUEST_URI';但问题在于 Nginx
      猜你喜欢
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2016-05-17
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多