Codeigniter url与index.php一起使用,也没有index.php

时间:2018-07-02 07:36:37

标签: php .htaccess codeigniter

我更改了配置并将其替换为

$config['index_page'] = '';

这是.htaccess

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

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

但是问题是我的两个URL都在工作,我希望它只能在没有index.php的情况下工作

https://www.example.com/index.php/example/xyz-abc

https://www.example.com/example/xyz-abc

2 个答案:

答案 0 :(得分:4)

请尝试使用以下代码,它可能会对您有所帮助。

config.php文件

$config['index_page'] = ""
$config['uri_protocol'] = "REQUEST_URI"

.htaccess文件

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

答案 1 :(得分:0)

请尝试使用以下代码,效果很好。使用以下代码重写.htaccess文件。

RewriteEngine on

RewriteBase /

RewriteCond $ 1!^(index.php | assets | artwork | adminAssets | galleryAssets | html | cache)

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