我该如何移除CodeIgniter中每个路径中突出显示的"index.php"
在某些地方位于中心位置?
我想要干净的没有index.php
的URL?
我该如何移除CodeIgniter中每个路径中突出显示的"index.php"
在某些地方位于中心位置?
我想要干净的没有index.php
的URL?
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
这里有另一个很好的版本:
RewriteCond $1 !^\/(index\.php|assets|robots\.txt)
- HenryRewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
| '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'] = 'ORIG_PATH_INFO';
RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]
$config['index_page'] = '';
将.htaccess文件与index.php文件放置在应用程序根目录中。(检查htaccess扩展名是否正确,因为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';
将变量empty设置如下。
$config['index_page'] = '';
就是这样,对我起作用了。
如果还不行,请尝试逐个替换以下变量('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI'和'ORIG_PATH_INFO')的参数。
$config['uri_protocol'] = 'AUTO';
请查看 system\application\config\config.php
文件,其中有一个名为 index_page
的变量。
它应该是这样的:
$config['index_page'] = "index.php";
将其更改为
$config['index_page'] = "";
如前所述,您还需要向.htaccess
文件添加重写规则。
注意:在CodeIgniter v2中,此文件已从system文件夹移动到application\config\config.php
中。
我尝试了以上所有方法,但都失败了。后来我发现,在我的虚拟主机文件/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>
...
步骤1 => 将您的.htaccess文件放置在应用程序和系统文件夹存在的根目录中。
步骤2 => 如果您的Web路径使用子文件夹,例如-yourdomain.com/project/,则在htaccess文件中使用以下代码
RewriteEngine on
RewriteBase /project/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /codeigniter/index.php/$0 [PT,L]
我想添加一些内容
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
替换
$config['uri_protocol'] = “AUTO”
使用
$config['uri_protocol'] = “REQUEST_URI”
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/$0 [PT,L]