1

我试图通过从我的 URL 中删除 index.php 来使我的网站的 URL 更清晰(并且对 SEO 友好),但发生了意外的结果,这是我的 .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。

4

1 回答 1

0

尝试三件事:

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

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

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

直接来自用户指南:

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

删除 index.php 文件

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

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

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

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

In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

于 2012-05-21T15:40:58.533 回答