【问题标题】:Get rid of Index.php in CodeIgniter URLs摆脱 CodeIgniter URL 中的 Index.php
【发布时间】:2014-07-20 21:47:29
【问题描述】:

如何从我的 URL 中删除“index.php”?

说明

使用 CI 构建简单的 MySQL-Php 应用程序,我无法摆脱 URL 内的“index.php”标签:

localhost/CodeIgniter/index.php/Defult_Controller/index

.htaccess

application/.htaccessapplication/cache/.htaccess

<IfModule mod_rewrite.c>

# !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/

RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
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>

apache.conf

LoadModule rewrite_module modules/mod_rewrite.so

应用程序/config/config.php

$config['base_url'] = "http://localhost/CodeIgniter/";
$config['index_page'] = '';

PS:我使用的是 codeIgniter 2.5.1 和 xampp 3.2.1

【问题讨论】:

  • 当您转到localhost/CodeIgniter/Defult_Controller/ 时会发生什么? 404?
  • @kasun 在描述中推荐截图。
  • 找不到对象!在此服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。如果您认为这是服务器错误,请联系网站管理员。错误 404 localhost Apache/2.4.7 (Win32) OpenSSL/0.9.8y PHP/5.4.22
  • 如果我没记错的话,你需要把你的.htaccess放到你的根文件夹里,去掉index.phpapplication/.htaccess是为了避免查看目录。

标签: php mysql apache .htaccess codeigniter


【解决方案1】:

你需要把你的.htaccess放到你的根目录下才能删除index.phpapplication/.htaccess是为了避免目录查看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    相关资源
    最近更新 更多