当我尝试从代码点火器URL中删除“索引.php”时,我被重定向到 domain.ltd(在chrome中)


When I tried to remove "Index.php" from codeigniter URL I get redirect to domain.ltd(in chrome)

我试图通过从我的URL中删除索引来使我的网站的URL更干净(和SEO友好.php但发生了意外的结果,这是我的.htaccess文件:

<IfModule mod_rewrite.c>
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /
    ### Canonicalize codeigniter URLs

    RewriteRule ^(site(/index)?|index('.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]
    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]
</IfModule>
<IfModule !mod_rewrite.c>
    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php
</IfModule>  

控制器是:site.php。

尝试三件事:

  1. 您是否从 config.php 文件中删除了索引.php

  2. 您是否尝试过直接使用 CI 提供的 htacces?

  3. $config['uri_protocol']设置为'AUTO';QUERY_STRING

直接来自用户指南:

http://codeigniter.com/user_guide/general/urls.html

删除索引.php文件

默认情况下,索引.php文件将包含在您的 URL 中:

example.com/index.php/news/article/my_article

您可以通过使用带有一些 .htaccess 文件的 .htaccess 文件轻松删除此文件 简单的规则。这是此类文件的示例,使用"负数" 重定向除指定项外的所有内容的方法:

RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

在上面的示例中,除索引.php之外的任何 HTTP 请求, 图像和机器人.txt被视为对索引的请求.php 文件。