繁体   English   中英

无法从实时站点的 codeigniter url 中删除 index.php

[英]unable to remove index.php from codeigniter url in live site

我需要从我的 codeigniter url 中删除 index.php。 这是我在 .htaccess 文件中的代码:

RewriteEngine On
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

和 config.php 文件中的修改:

$config['base_url'] = 'http://example.com/'
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

在我的本地主机上工作正常。 但在我的实时站点中,它会生成 404 错误。

我可以使用 index.php (' http://example.com/index.php/Home ') 加载 url,但是 ' http://example.com/Home ' 会产生 404 错误。 为什么这只发生在现场? 是否需要其他更改? 还有一件事,它不是 apache 服务器,我的网站是在 iis 中发布的

将以下代码粘贴到您的 .htaccess 文件中

   RewriteEngine On
   #RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule (.*) index.php/$1

然后转到 config 文件夹中的配置文件并从中删除 index.php

   $config['index_page'] = '';

如果您的站点位于子文件夹中,则必须在“#RewriteBase /”之后添加子文件夹名称

我想你不见了

重写基数 /

这是完整的 htaccess,它应该位于主项目文件夹中。 如果它在子文件夹中,您必须编写 rewritebase。

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM