[英]htaccess codeigniter remove index.php
我已经在apache2.4和php7.2 docker环境中托管了codeigniter应用程序。 无法正确解析路由。
路径
在/ var / www / html等/应用/ SAMPLE1
浏览器路径
工作正常,但直到我使用index.php时,路由控制器和动作才能得到解决
正确的期望
.htaccess当前配置,Apache mod_rewrite已启用
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/innovative_travel_web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [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_php5.c>
php_value short_open_tag 1
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
</IfModule>
请指导我,我该如何解决。
尝试这个:
1)编辑config.php
$config['index_page'] = 'index.php';
至
$config['index_page'] = '';
2)创建/编辑.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>
1)像这样创建htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|asset)
RewriteRule ^(.*)$ index.php?/$1 [L]
Options -Indexes
2)在application / config / config.php文件中
$config['index_page'] = '';
在config.php中设置
$config['index_page'] = '';
然后,根据根文件夹,您的.htaccess和RewriteBase
可能如下所示/
如果应用程序在根文件夹中运行,则为/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder_name/
RewriteCond $1 !^(index\.php|images|robots\.txt)
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#This snippet prevents user access to the application folder
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>
ErrorDocument 404 /index.php
</IfModule>
在config.php中设置
$config['index_page'] = '';
在.hta
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /apps/sample1/index.php/$1 [L]
</IfModule>
您还需要指定目录,因为您的路径是/ var / www / html / apps / sample1而不是/ var / www / html /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.