簡體   English   中英

CodeIgniter從url中刪除index.php

[英]CodeIgniter removing index.php from url

我知道這個問題已被問過很多次了。 但是,我仍然無法擺脫index.php網址。 它阻止我直接訪問我的控制器。

我目前正在使用CodeIgniter 2.2.2
以下是我的.htaccess文件:

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

應用程序/配置:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

任何的想法? 在此先感謝您的時間。

在.htacess中使用以下代碼

   DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

試試這個..

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

我之前遇到過同樣的問題。 這就是我做的

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

然后轉到config.php並刪除index.php

$config['index_page'] = 'index.php';
//change it to
$config['index_page'] = '';

如果你使用wamp確保你啟用了apache mod rewrite。

這個htaccess適用於wamp或xampp

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

確保它放在主目錄中。

$config['index_page'] = '';

CI用戶手冊

Index.php文件將作為默認值包含在您的URL中。

例:

example.com/index.php/controller

你怎么改變?

您可以使用.htaccess中的重寫規則從URL中刪除index.php

用戶指南中的示例:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

使用“否定”方法,其中除指定的項目外,所有內容都被重定向。

最后一件事讓你使用index_page作為空位置application / config / config.php:

$config['index_page'] = '';

最后,如果您仍然面臨問題,請將uri_protocol AUTO更改為REQUEST_URI

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

這對我有用。

RewriteEngine on 
RewriteCond $1 !^(index.php|resources|robots.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

在你的.htaccess上

RewriteEngine On

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

$config['index_page'] = '';

為我工作

最后解決了我的問題。 我想與大家分享我的答案。 我目前正在使用mac,我將.htaccess文件重命名為htaccess.txt並在htaccess中包含以下代碼:RewriteEngine On

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
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

然后通過執行以下操作確保Apache正在讀取htaccess.txt文件:

  1. 在httpd.conf上取消注釋以下行

  2. 進入extra / httpd-default.conf文件並更改以下代碼行: AccessFileName .htaccessAccessFileName htaccess.txt

  3. 重啟Apache服務器

  4. 在配置中,確保將“base_url”留空(索引頁仍然可以存在,無關緊要)。 並且$ config ['uri_protocol'] ='REQUEST_URI';

希望這可以幫助其他人!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM