CodeIgniter从url中删除index.php

我目前的url看起来像这个[mysite]index.php/[rest of the slug]
我想从这些url去掉index.php

mod_rewrite在我的apache2服务器上启用。 在config$config['index_page'] = '';

我的codeignitor根.htaccess文件包含,

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] 

但还是不行。 我哪里错了?

尝试以下

打开config.php并做下列replace

 $config['index_page'] = "index.php" 

 $config['index_page'] = "" 

在某些情况下, uri_protocol的默认设置无法正常工作。 只要更换

 $config['uri_protocol'] ="AUTO" 

通过

 $config['uri_protocol'] = "REQUEST_URI" 

的.htaccess

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

注意:.htaccess代码因托pipe服务器而异。 在一些托pipe服务器(如:Godaddy)需要使用额外的? 在上面的代码的最后一行。 在适用情况下,以下行将被最后一行replace:

 // Replace last .htaccess line with this line RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

步骤:-1打开文件夹“application / config”并打开文件“config.php”。 在config.php文件中find并replace下面的代码。

 //find the below code $config['index_page'] = "index.php" //replace with the below code $config['index_page'] = "" 

步骤:-2转到您的CodeIgniter文件夹并创build.htaccess

 Path: Your_website_folder/ application/ assets/ system/ .htaccess <——— this file index.php 

步骤:-3在.htaccess文件中写下面的代码

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

步骤:-4在某些情况下,uri_protocol的默认设置无法正常工作。 要解决这个问题,只需打开文件“application / config / config.php”,然后find并replace下面的代码

 //find the below code $config['uri_protocol'] = "AUTO" //replace with the below code $config['uri_protocol'] = "REQUEST_URI" 

多数民众赞成所有,但在WAMP服务器它不工作,因为rewrite_module默认情况下禁用,所以我们需要启用它。 为此做以下

  1. 左键单击WAMP图标
  2. 阿帕奇
  3. Apache模块
  4. 左键单击rewrite_module

链接

步骤1 :

把它添加到htaccess文件中

 <IfModule mod_rewrite.c> RewriteEngine On #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] </IfModule> 

第2步 :

在codeigniterconfiguration中删除index.php

 $config['base_url'] = ''; $config['index_page'] = ''; 

第3步:

允许在Apacheconfiguration中覆盖htaccess(命令)

 sudo nano /etc/apache2/apache2.conf 

并编辑文件并更改为

 AllowOverride All 

为www文件夹

步骤4 :

启用apache mod重写(命令)

 sudo a2enmod rewrite 

第5步:

重启Apache(命令)

 sudo /etc/init.d/apache2 restart 
 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] 

使用

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$1 [PT,L] 

如果你有这个订单的网站site.com/index.php/class/method/id

注意:在config.php中删除index.php应该是config [index_page] =“”

注意:注意最后一行的差异,而不是$ 0使用$ 1

步骤1 =>将.htaccess文件放在应用程序和系统文件夹所在的根文件夹中。

步骤2 =>如果您的networkingpath使用子文件夹 – yourdomain.com/project/ – 然后在htaccess文件中使用以下代码

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

如果您的networkingpath使用根文件夹 – yourdomain.com – 然后在htaccess文件中使用以下代码

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

有两个步骤:

1)编辑config.php

 $config['index_page'] = 'index.php'; 

 $config['index_page'] = ''; 

2)创build/编辑.htaccess文件

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

在你的htaccess上使用这个,

 RewriteEngine On RewriteBase /root_folder_name/ 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] 

希望这可以帮助。

 + Copy .htaccess from Application to Root folder + edit .htaccess and put <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /ci_test/ #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 %{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> Note: make sure your web server is enable for "rewrite_module" + Remove index.php from $config['index_page'] = 'index.php'; - edit config.php in application/config - search for index.php change it from $config['index_page'] = 'index.php'; to $config['index_page'] = ''; 

请观看此video以供参考https://www.youtube.com/watch?v=HFG2nMDn35Q

  1. 使.htaccess文件,并把这个代码

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

     $config['index_page'] = ''; 

删除config.php文件中的index.php

  1. 从你的服务器重写。

首先你必须在apache服务器上重写引擎on.this链接将帮助你

http://www.anmsaiful.net/blog/php/enable-apache-rewrite-module.html

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

这将是你的.htaccess文件。 现在试试看。这个设置对我来说很有用。

试试这个,它可以帮助你为我工作。

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] 

把代码放在你的根htaccess文件中,并确保你有

 $config['index_page'] = ''; 

在你的configuration文件中。

如果您遇到任何问题,请告诉我。

  Removing index.php from url of codeigniter Three steps are require to remove index.php from url in Codeigniter. 1)Create .htacess file in parallel to application holder and just copy past the following code: RewriteEngine On RewriteBase /CodeIgniter/ RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 2) Change $config['index_page'] to blank in config.php in application folder as below: $config['index_page'] = ''; 3) Enable “rewrite_module” of apache. 

无论是开发还是生产

  # Development RewriteEngine On RewriteBase /your_local_folder/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] #Production PHP5 CGI mode RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt) RewriteRule ^(.*)$ index.php?/$1 [L] 

你可以去config \ config.php文件,并从这个variables中删除index.php值

 $config['index_page'] = 'index.php'; // delete index.php 

创build.htaccess文件并粘贴这个代码。

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

好机会

我认为你的所有设置是好的,但你做错了你的htaccess文件去添加你的htaccess到你的项目文件

project_folder-> htaccess的

并将此代码添加到您的htaccess

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

只需要三步就可以从Codeigniter的url中删除index.php

1)与应用程序持有者并行创build.htacess文件,只需复制以下代码:

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

2)在应用程序文件夹的config.php中将$ config ['index_page']更改为空白如下:

 $config['index_page'] = ''; 

3)启用apache的“rewrite_module”。

重新启动你的Apache并完成。

详情: http : //sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

按照这些步骤你的问题将得到解决

1-从这里下载.htaccess文件https://www.dropbox.com/s/tupcu1ctkb8pmmd/.htaccess?dl=0

2-在第5行更改CodeIgnitor目录名称。 就像我的目录名是abc(添加你的名字)

3-将.htaccess文件保存在codeignitor文件夹的主目录(abc)中

4-在Config.php文件中将uri_protocol从AUTO更改为PATH_INFO

注意:首先你必须通过删除注释来从apachi的httpd.conf启用mod_rewrite

使用这个代码。 更改第二行,因为你有你的文件夹名称。 其中index.php文件和文件夹应用程序,系统文件夹谎言。 大部分问题都是由于第二行发生的。 我们不configuration项目所在的文件夹名称。 重要的是第二行。 这很容易删除index.php。 RewriteEngine on RewriteBase / project_folder_name RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule。* index.php / $ 0 [PT,L]

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

转到controller / config.php文件。

configuration[ 'index_url'] = '';

参考更多的研究。

https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

https://ellislab.com/blog/entry/fully-removing-index.php-from-urls

在根目录下创build一个新的.htaccess文件。

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

除了这些答案之外,还可以添加index.php或者编辑它(如果已经存在的话) – 为了安全起见,无论如何你都要禁用index.php,从列出你的网站目录中的文件 – 然后把内容改成

 <?php header('location:your_required_starting.php'); ?> 

你可以去application \ config \ config.php文件并删除index.php


  $ config ['index_page'] ='index.php';  //删除index.php

改成


  $ config ['index_page'] ='';

在你的.htaccess文件中添加这些代码行:

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

在哪里“我的项目是你的项目文件夹名称。

你可以阅读更多关于CodeIgniter或者你可以从这里下载.htaccess文件

那么这些答案都是好的,但对于新手来说(这是第一次),这些都是令人困惑的。 还有其他的htaccess文件驻留在控制器中,但我们必须在主工程文件夹中编辑或添加htaccess。

这是您的codeigniter文件夹,其中文件驻留在应用程序,系统,资产,上传等

 Your_project_folder/ application/ assets/ cgi-bin/ system/ .htaccess---->(Edit this file if not exist than create it) index.php 

改变这个文件如下所示:

 <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/ # Otherwise / 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: Anand Pandey ErrorDocument 404 /index.php </IfModule> 

是的,当然你需要在application / config / config.php中更改两行代码

 //find the below code $config['index_page'] = "index.php"; $config['uri_protocol'] ="AUTO" //replace with the below code $config['index_page'] = ""; $config['uri_protocol'] = "REQUEST_URI"; 

次要的事情:(可选)

尝试在vhosts中将重写引擎状态更新为Rewrite ON后重新启动Apache。

一个重要的事情要注意:

在Apache vhosts文件中,检查是否有此脚本行AllowOverride None如果是, 请删除/注释此行。

我的虚拟主机文件脚本:(之前)

 <VirtualHost *:80> DocumentRoot "/path/to/workspace" ServerName ciproject ErrorLog "/path/to/workspace/error.log" CustomLog "/path/to/workspace/access.log" common Directory "/path/to/workspace"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> 

我的虚拟主机文件脚本:(后)

 <VirtualHost *:80> DocumentRoot "/path/to/workspace" ServerName ciproject ErrorLog "/path/to/workspace/error.log" CustomLog "/path/to/workspace/access.log" common Directory "/path/to/workspace"> Options Indexes FollowSymLinks #AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> 

我面临同样的问题,挣扎了大约1天,一切都很好。 后来通过试错法,发现了这个东西。 删除后,我的工作就完成了。 该URL现在不查找index.php 🙂