【问题标题】:Write multiple rewrite rules in .htaccess在 .htaccess 中编写多个重写规则
【发布时间】:2016-07-07 19:25:39
【问题描述】:

我当前的 codeigniter .htaccess 是:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com [L,R=301,NC]

并且放置了 2 个 .htaccess。 一个在根目录,另一个在应用程序文件夹中。

我想一次写以下重写规则:

1. 删除 index.php

2. 强制将 www.example.com 重定向到 https://example.com

3. 强制将 http.example.com 重定向到 https://example.com

4. 强制将 www.example.com/cart 重定向到 https://example.com/cart

【问题讨论】:

    标签: .htaccess codeigniter mod-rewrite codeigniter-2 codeigniter-3


    【解决方案1】:

    试试这个:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com$
    RewriteRule ^(.*) https://example.com/$1 [QSA,L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
    

    在 config.php (codeignter) 中:

    $config['index_page'] = '';
    

    希望对你有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-10
      • 2013-02-14
      • 2015-02-15
      • 2017-11-21
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多