简体   繁体   English

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

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

I need to remove index.php from my codeigniter url.我需要从我的 codeigniter url 中删除 index.php。 This is my code in .htaccess file :这是我在 .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]

and modifications in config.php file :和 config.php 文件中的修改:

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

working fine in my localhost.在我的本地主机上工作正常。 but in my live site it generates a 404 error.但在我的实时站点中,它会生成 404 错误。

I can load the url with index.php (' http://example.com/index.php/Home '), but ' http://example.com/Home ' generates 404 error.我可以使用 index.php (' http://example.com/index.php/Home ') 加载 url,但是 ' http://example.com/Home ' 会产生 404 错误。 Why this only happens in live site?为什么这只发生在现场? is there any other changes need?是否需要其他更改? one more thing, its not an apache server, my site is published in iis还有一件事,它不是 apache 服务器,我的网站是在 iis 中发布的

Paste the below code in your .htaccess file将以下代码粘贴到您的 .htaccess 文件中

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

then go to your config file in config folder and remove index.php from然后转到 config 文件夹中的配置文件并从中删除 index.php

   $config['index_page'] = '';

if you site is in the sub folder then you have to add the subfolder name after "#RewriteBase /"如果您的站点位于子文件夹中,则必须在“#RewriteBase /”之后添加子文件夹名称

I think that you are missing我想你不见了

RewriteBase /重写基数 /

Here is the full htaccess which should be reside on main project folder.这是完整的 htaccess,它应该位于主项目文件夹中。 You have to write the rewritebase if it is on subfolder.如果它在子文件夹中,您必须编写 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