我正在 CodeIgniter 3 中做一个项目。我需要从 url 中删除
index.php
。为此,请帮助我获取 CodeIgniter 3 的 .htaccess
文件以及放置此文件的位置。
这是我的基本网址
http://cableandmedia.com/demo/
使用以下代码更新您的 htaccess 文件
RewriteEngine On
RewriteBase /demo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
并在配置文件中,请使用以下代码更改基本网址:-
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
将 .htacces 文件放在根目录中并使用以下代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
.htaccess
处创建root
文件.htaccess
<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/
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>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: "*"
</IfModule>
2.删除
root/application/config/config.php
处的index.php
$config['index_page'] = '';
3.如果您的服务器是新的 |您的服务器重写模式被拒绝打开终端通过 SSH 连接您的服务器键入下面的代码
sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/apache2.conf
之后请检查
AllowOverride
是否为All
<Directory “/var/www”>
AllowOverride All
</Directory>
文件:config.php
$config['index_page'] = '';
文件:.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine 允许您重写进入服务器的 URL 请求,并且基于正则表达式解析器。
在您的
config.php
中进行以下更改。
$config['index_page'] = '';
并在主项目目录中添加
.htaccess
文件,内容如下
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
嗯,
这是我所做的,
我为此编辑/创建了“.htaccess”
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
和“app/config/config.php”
$config['base_url'] = '';
$config['uri_protocol'] = 'AUTO';
和“app/libraries/Template.php”
define("PATH", base_url()."index.php/");
define("BASE", base_url());
干杯!
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
$config['base_url'] = 'PUT YOUR BASE URL HERE';
$config['index_page'] = '';
1. open your .htaccess file present in the root and add the below code :-
RewriteEngine On
RewriteBase /demo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
2. Now in your config.php file
update this line of code :- $config['index_page'] = '';