繁体   English   中英

CodeIgniter Mod_Rewrite问题

[英]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>

配置项设置:

$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'] = '';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM