HTACCESS考虑现有规则重写为HTTPS

时间:2013-10-19 17:59:17

标签: .htaccess mod-rewrite redirect

我要求命名索引文件的请求删除索引文件文件名,并强制非www在这里:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/ 
RewriteRule ^(([^/]*/)*)index\.(html?|php)$  http://techsupportheroes.com/$1  [R=301,L] 

但我需要将所有请求重定向到http://techsupportheroes.com/cart/index.phphttps://techsupportheroes.com/cart/index.php

这不是我的专业领域。寻找一个优雅的解决方案,如果有人有一个时刻。

谢谢, 埃里克

2 个答案:

答案 0 :(得分:0)

试试这段代码:

RewriteEngine On

# remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://$1%{REQUEST_URI} [R=301,NE,L]

# remove index.html
RewriteCond %{THE_REQUEST} /index\.(html?|php) [NC]
RewriteRule ^(([^/]*/)*)index\.(html?|php)$  http://techsupportheroes.com/$1 [NC,R=301,L]

#force https for /cart/index.php
RewriteCond %{HTTPS} off
RewriteRule ^(cart)/index\.php$ https://%{HTTP_HOST}/$1/ [R=301,L,NC]

答案 1 :(得分:0)

  

“我需要将所有请求重定向到   http://techsupportheroes.com/cart/index.php来   https://techsupportheroes.com/cart/index.php

试试这个:

RewriteEngine On
#not https
RewriteCond %{HTTPS} off
RewriteRule /cart/index.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]