Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除“;index.php“;在codeigniter';s路径_Php_Mod Rewrite_Codeigniter_Url Rewriting - Fatal编程技术网

如何删除“;index.php“;在codeigniter';s路径

如何删除“;index.php“;在codeigniter';s路径,php,mod-rewrite,codeigniter,url-rewriting,Php,Mod Rewrite,Codeigniter,Url Rewriting,我如何删除codeigniter中位于中心某个位置的每个路径中突出的“index.php”? 我想要干净的非index.php-fied URL?按照CI wiki中的说明使用mod\u rewrite。这是我的一个CI项目的.htaccess: RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|robots\.txt) RewriteRule ^(.*)$ /projectFolder/index.php/$1 [L]

我如何删除codeigniter中位于中心某个位置的每个路径中突出的
“index.php”

我想要干净的非
index.php-fied URL

按照CI wiki中的说明使用
mod\u rewrite

这是我的一个CI项目的.htaccess:

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

最后一行应该提供您所需的内容,尽管您可能需要也可能不需要“/projectFolder”,这取决于文件夹结构的设置方式。祝你好运

查看
system\application\config\config.php
文件,其中有一个名为
index\u page的变量

应该是这样的

$config['index_page'] = "index.php";
$config['index_page'] = "index.php";
换成

$config['index_page'] = "";
$config['index_page'] = "";
然后,如前所述,您还需要将重写规则添加到
.htaccess
文件中


注意:在CodeIgniter v2中,如果您正在使用Apache,则该文件已从系统文件夹中移出到
application\config\config.php

,并在根web目录中放置一个.htaccess文件,其中包含以下内容:

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
另一个好的版本位于此处:


我在删除index.php时遇到了一些大问题。作为一般规则,下面的.htaccess已在多台服务器上进行了测试,通常可以正常工作:

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

<Files "index.php">
AcceptPathInfo On
</Files>  
如果您仍然运气不佳,请尝试更改重写规则以包含您的子文件夹。如果您在开发服务器上使用临时URL等,这通常是一个问题:

RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]  
只要玩转这些选项,就可以了。此外,请确保将索引文件设置为:

$config['index_page'] = '';

祝你好运

我只是想补充一下

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
将是.htaccess,请确保按以下方式编辑application/config.php变量:

替换

$config['uri_protocol'] = “AUTO” 


所有上述方法对我来说都失败了,然后我发现我没有将虚拟主机文件中的/etc/apache2/sites available/default中的AllowOverride None更改为AllowOverride All

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All    <---- replace None with All
    </Directory>
    <Directory /var/www >
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All   <---  replace None with All
            Order allow,deny
            allow from all
    </Directory>

     ...

服务器管理员webmaster@localhost
DocumentRoot/var/www
选项如下符号链接

AllowOverride All将.htaccess文件放在根web目录中


无论你做什么调整——如果不满足上述要求——都不会起作用。通常它在系统文件夹中,它应该在根目录中。干杯

将.htaccess文件与index.php文件一起放在应用程序根目录中。(检查htaccess扩展是否正确,Bz htaccess.txt对我不起作用。)

并将以下规则添加到.htaccess文件中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  
然后在application/config/config.php文件中找到以下行

$config['index_page'] = 'index.php';
将变量设置为空,如下所示

$config['index_page'] = '';
就是这样,对我来说很有效

如果不起作用,请尝试用这些参数逐个替换以下变量(“自动”、“路径信息”、“查询字符串”、“请求URI”和“原始路径信息”)

$config['uri_protocol'] = 'AUTO';
这肯定有用。。试一试

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /codeigniter/index.php/$0 [PT,L]
更改RewriteRule.*index.php/$0[PT,L],项目文件夹名为“codeigniter”。这对我很有用。谢谢你们的支持


我在apache2上测试了许多不同的主机,效果非常好

使用此htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
确保已使用
phpinfo()启用mod_rewirte

然后在config/config.php中执行此操作:

$config['index_url']    = '';
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
如果它还不能工作,请尝试将
$config['uri_protocol']='AUTO'
更改为第40/54行
application/config/config.php中列出的文件之一:


有时我使用:
REQUEST\u URI
而不是
AUTO
为goDaddy hostings使用
QUERY\u STRING
确保启用了
mod\u rewrite
(我没有启用)。
要启用:

sudo a2enmod rewrite  
另外,将
AllowOverride None
替换为
AllowOverride All

sudo gedit /etc/apache2/sites-available/default  
最后

sudo /etc/init.d/apache2 restart  
我的.htaccess是

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

\application\config\config.php
文件中,有一个名为
index\u页面的变量

应该是这样的

$config['index_page'] = "index.php";
$config['index_page'] = "index.php";
换成

$config['index_page'] = "";
$config['index_page'] = "";
然后,如前所述,您还需要向
.htaccess
文件添加重写规则,如下所示:

RewriteEngine on
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
这对我有用,希望你也有用。

这将对你有所帮助 将此代码粘贴到.htacess文件的应用程序文件夹中

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

<Files "index.php">
AcceptPathInfo On
</Files>
<IfModule mod_php5.c>
  php_value short_open_tag 1
</IfModule>
重新编写引擎打开
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
上的AcceptPathInfo
php_值short_open_标记1

作为一个.htaccess文件,一个好的选择是使用以下文件提供的文件:

#启用URL重写
重新启动发动机
#安装目录
重写基/
#保护隐藏文件不被查看
命令拒绝,允许
全盘否定
#保护应用程序和系统文件不被查看
重写规则^(?:应用程序|系统)\b.*index.php/$0[L]
#允许直接显示现有的任何文件或目录
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#将所有其他URL重写为index.php/URL
重写规则。*index.php/$0[PT]

这是一个经过深思熟虑的解决方案。htaccess很管用。

我尝试了很多解决方案,但我想到的是:

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots  \.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
这将根据需要从url中删除index.php。

完美解决方案[在本地主机和真实域上测试] 步骤1=>将.htaccess文件放在存在应用程序和系统文件夹的根文件夹中

步骤2=>如果您的web路径使用子文件夹-yourdomain.com/project/-那么在htaccess文件中使用以下代码

<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [QSA,L] 
</IfModule>
如果您的web路径使用根文件夹(如-yourdomain.com),请在htaccess文件中使用以下代码

<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [QSA,L] 
</IfModule>

如果您在linux上并且使用apache2服务器,那么除了对.htaccess文件的更改之外,我们可能还需要覆盖apache2.conf文件。在/etc/apache2/apache2.conf上查找apache2配置文件

搜索目录/var/www/ChangeAllowOverride None->AllowOverride All

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory

选项索引跟随符号链接
允许超越所有
要求所有格兰
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory
RewriteEngine on
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
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
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
RewriteEngine on
Options -Indexes
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
$config['index_page'] = 'index.php';
$config['index_page'] = '';
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Foldername of your ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [QSA,L] 
</IfModule>
$config['base_url'] = ''; 
$config['index_page'] = '';
AllowOverride All
sudo /etc/init.d/apache2 restart