CodeIgniter Mod_Rewrite issues



删除index.php时出现问题?来自URL:

http://localhost/index.php?/reset_password

使用htaccess文件:

# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

CI设置:

$config['uri_protocol'] = 'AUTO';

我查看了这里其他有类似问题的线程,但它们的htaccess文件都不起作用。我是不是错过了一个场景?

我以前从未见过.htaccess设置,尽管它可能有效。我做过的每一个CI项目都用过这个,试试看:

<IfModule mod_rewrite.c>
    RewriteEngine on
    # If the start of the URL doesn't match one of these...
    RewriteCond $1 !^(index.php|robots.txt|assets|cache|themes|uploads)
    # Route through index.php
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

config.php:中添加"不要忘记"

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

请记住:这不会自动从您的URL中"删除"index.php,而是在请求不存在的情况下通过它进行路由。如果您有包含index.php的硬编码链接,则必须对其进行更改,或者需要额外的.htaccess配置。如果您使用的是base_url()site_url()anchor()等CI url函数,那么如果您在上面的配置中为空,它们就不会使用index.php

此代码适用于我:

如果我的站点名称是codeIgniter_ci_intro

我在.htaccess 中使用了代码

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

并且我更改了config.php

$config['index_page'] = '';

最新更新