【问题标题】:CodeIgniter Redirection with .htaccess giving errorCodeIgniter 重定向与 .htaccess 给出错误
【发布时间】:2019-04-12 16:23:38
【问题描述】:

我在使我的网站 url 对 seo 友好时遇到问题。所以我想将下面的所有网址重定向到http://example.in/

http://example.in/index.php
http://www.example.in/
http://www.example.in/index.php
http://www.example.in/Home
http://www.example.in/Home/
http://www.example.in/Home/index

我的 .htacces 看起来像

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

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.example.in$
RewriteRule ^(.*)$ http://example.in/$1 [R=301]
</IfModule>

配置文件看起来像

$config['index_page'] = ''; 
$config['base_url'] = 'http://example.in/'; 
$config['uri_protocol'] = 'REQUEST_URI';

问题是这 3 个 url 重定向得很好。

http://example.in/index.php
http://www.example.in/
http://www.example.in/index.php

但是在检查别人的时候

http://www.example.in/Home
http://www.example.in/Home/
http://www.example.in/Home/index

他们重定向到 index.php?作为

http://www.example.in/index.php?/Home
http://www.example.in/index.php?/Home/
http://www.example.in/index.php?/Home/index

如果我添加删除 index.php 的代码,或者像这样

http://www.example.in/?/Home
http://www.example.in/?/Home/
http://www.example.in/?/Home/index

这是为什么?/来了?

【问题讨论】:

    标签: codeigniter url-redirection .htaccess


    【解决方案1】:

    您的问题出在这一行,您在 index 之前缺少一个“./”,而您在 index.php 前面有一个“?”:

    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    您必须将其更改为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 2014-01-30
      • 2019-11-21
      相关资源
      最近更新 更多