结合htaccess重写

时间:2012-08-29 21:20:14

标签: php .htaccess url url-rewriting

我正在使用php CodeIgniter并在我的.htaccess文件中有以下重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

由于我希望用户通过SSL使用该网站,我想添加以下重写规则:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]

但是,当我这样做时,子目录中的每个页面都会有/index.php/actual_page - 之前的index.php是不可取的。我认为这可能来自RewriteRule ^(.*)$ index.php/$1 [L],但没有RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]它可以正常工作。

那么,如何在不破坏第一次重写的情况下将url重写为https?

1 个答案:

答案 0 :(得分:1)

确保在重写为index.php之前发生https重定向。你希望它看起来像这样:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]