使用cakePHP重定向.htaccess

时间:2014-09-06 15:25:33

标签: php .htaccess cakephp redirect

cakePHP已经在/web/website/.htaccess

上设置了它
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

现在我想将所有http重定向到https,将www重定向到非www

我试过了:

 RewriteEngine on
Options +FollowSymlinks -MultiViews


  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteRule ^$ app/webroot/    [L]
RewriteRule (.*) app/webroot/$1 [L]

INPUT:http://www.example.com.br/website OUTPUT:https://example.com.br/内部服务器错误 应该:https://example.com.br/website

2 个答案:

答案 0 :(得分:1)

使用整个请求URI尝试而不是使用$1

RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]

答案 1 :(得分:0)

<IfModule mod_rewrite.c>
 RewriteEngine on

 // HTTP => HTTPS
 RewriteCond %{HTTPS} off
 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 // www => http
 RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
 RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

 RewriteRule ^$ app/webroot/ [L]
 RewriteRule (.*) app/webroot/$1 [L]
</IfModule>