正在从Codeigniter 3中的URI中删除index.php



我已经完成了从URI中删除"index.php"的所有上述解决方案。我采取的步骤如下:In.htaccess:

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

在config.php 中

base_url设置为

$config['base_url'] = 'https://trawellmate.com/';

从中删除了index.php

$config['index_page'] = '';

这些是建议的解决方案。但什么都没用。我正在使用SSL,所有非请求都重定向到https://trawellmate.com.以下是为在.htaccess:中实现而添加的行

#FORCE NON-WWW REDIRECT
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

早期使用非SSL(在localhost中处于开发模式(时,它运行良好。由于我们即将上线,我们将非常感谢您的快速帮助。

您可以尝试使用以下规则。它对我有效。

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www. [OR]
RewriteCond %{HTTP_HOST} ^yourwebsite.com$ [NC]
RewriteRule ^ https://www.yourwebsite.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+ /index.php(/[^ ]*)? HTTP/ 
RewriteRule ^index.php(/(.*))?$ yourwebsite.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

允许在Apache配置(命令(中重写htaccess

sudo nano /etc/apache2/apache2.conf

并编辑文件&更改为

AllowOverride All

下面.htaccess配置适用于我的

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

我已经将.htaccess文件放在/var/www/html中,即与应用程序目录并行

希望您已经为apache启用了mod_rewrite模块,还可以在apache的virtualhost文件(000default.conf(中添加以下块。更改后请重新启动服务器。

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

最新更新