【问题标题】:Removing index.php in codeigniter xampp for windows在 Windows 的 codeigniter xampp 中删除 index.php
【发布时间】:2015-08-17 10:16:44
【问题描述】:

我尝试了所有可以找到的方法,包括在这个网站上。但是重定向不起作用。

My config.php

    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'];

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

重写引擎开启

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L] 




RewriteCond %{HTTP_HOST} ^www.**.ru$ [NC]
RewriteRule ^(.*)$ http://**.ru/$1 [R=301,L]


RewriteCond $1 !^(robots\.txt|index\.php|image\.php|favicon\.ico|upload|sotrudnik|generator|links|assets|agents|old|sitemap\.xml|4cc707e99fb15630dc\.html|sitemap_mobile\.xml|yandex_6bfb7e8daf6b3458\.html|holder\.js)
RewriteRule ^(.*)$ /index.php/$1 [L]

这个.htaccess

【问题讨论】:

  • 你找到解决办法了吗?

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

您可以使用Apache的mod-rewrite将不包含“index.php”的路径重写为/index.php/***路径,例如这样:

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/$1 [L]

我认为你应该恢复 $config['index_page'] 的原始值:这不是解决方案,它可能有缺点

【讨论】:

  • 是否启用了 mod_rewrite 模块? Apache 的错误日志是怎么说的?
【解决方案2】:

您可以尝试使用以下 .htaccess:

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

请像下面这样更改您的 config.php:

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

不要忘记启用mod_rewrite

【讨论】:

    【解决方案3】:

    我使用 windows 和 xampp。

    在主目录中使用这个 htaccess

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

    在主目录中创建 htaccess 后,转到 config.php 查找 index_page 确保如下所示为空白

    $config['index_page'] = '';
    

    更多示例在这里https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter

    您可能还需要在 application/config/routes.php 中配置您的路由

    http://www.codeigniter.com/user_guide/general/routing.html

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2012-03-26
      • 1970-01-01
      • 2021-12-15
      • 2021-04-11
      • 2011-02-02
      • 2015-04-23
      • 2014-08-19
      • 1970-01-01
      相关资源
      最近更新 更多