在默认 var/www/html 文件夹内的实时服务器中,如果没有 index.php

Codeigniter 路由在本地服务器中工作。当我部署到var/www/html服务器时,路由无法按预期工作。


当我index.php在 URL 中添加控制器名称之前,它工作正常。


但没有index.php,它会抛出 404 page not found 错误


.htaccess文件


RewriteEngine On


RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

我也试过这个


<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /var/www/html/

    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /index.php [L]

</IfModule>

但没有任何效果..


桃花长相依
浏览 214回答 3
3回答

天涯尽头无女友

您的服务器中似乎未启用 mod_rewrite。如果重写规则不起作用,请确保您在 Apache 配置文件中允许 .htaccess 文件。目录部分应包含 AllowOverride All 选项:<Directory "/var/www/html">&nbsp; &nbsp;Options Indexes FollowSymLinks&nbsp; &nbsp;AllowOverride All&nbsp; &nbsp;Order allow,deny&nbsp; &nbsp;Allow from all</Directory>不要忘记对 Apache 配置文件的任何更改都需要重新启动服务!

凤凰求蛊

尝试以下解决方案:转到 application\config\config.php 文件做出改变$config['index_page'] = 'index.php';至$config['index_page'] = '';.htaccess<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /YourCIFolderName/RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /YourCIFolderName/index.php [L]</IfModule>

慕村9548890

步骤1去 application/config/config.php 找到$config['index_page'] = 'index.php';change it to$config['index_page'] = '';第2步转到 application/config/routes.php评论结束后从页面底部删除所有内容并粘贴以下代码$route['default_controller'] = 'main'; // main is your default controller name$route['404_override'] = '';$route['translate_uri_dashes'] = FALSE;$route['(:any)'] = "main/$1";$route['admin'] = 'admin/login';第 3 步在根文件夹中添加一个名为 .htaccess 的新文件,其中包含名为 application 和 system 等的文件夹添加以下代码并打开网站&nbsp;RewriteEngine OnRewriteBase /Options All -IndexesRewriteCond %{REQUEST_METHOD} POST [NC]RewriteRule ^ - [L]<IfModule mod_rewrite.c>RewriteCond %{HTTP_HOST} !^www\. [NC]RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]</IfModule># remove index.phpRewriteCond %{REQUEST_METHOD} !POSTRewriteCond %{THE_REQUEST} /index\.php [NC]RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]RewriteRule ^ %1 [L,R=301,NE]# To externally redirect /dir/file.php to /dir/fileRewriteCond %{REQUEST_METHOD} !POSTRewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]RewriteRule ^ /%1 [R=301,NE,L]# To internally forward /dir/file to /dir/file.phpRewriteCond %{DOCUMENT_ROOT}/$1.php -fRewriteRule ^(.+?)/?$ $1.php [L]Header set Access-Control-Allow-Origin "*"RewriteEngine onRewriteCond $1 !^(index\.php|resources|robots\.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?/$1 [L,QSA]&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP