douzhuanqian8244
2015-08-23 23:22
采纳率: 100%
浏览 54
已采纳

透明地将http://my-domain-name.com重定向到https://my-domain-name.com/web

I have a website with my front controller in a subdirectory. Then I would like to transparently redirect root folder of the site to subdirectory. Moreover, I have SSL enabled and want to force it for the site.

I succeeded in transparently redirecting root folder to subdirectory by doing this in .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

So I decided to add https to the RewriteRule like this : RewriteRule ^(.*)$ https://my-domain-name.com/web/$1 [QSA,L]. But I don't get what I want. In fact, I get https forcing but the transparent root folder to subdirectory redirection does not work anymore. I got in my address bar : https://my-domain-name.com/web though my wish is to have https://my-domain-name.com.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmoyu0336 2015-08-23 23:36
    已采纳

    Your added rule is implicitly treated like a redirect. Just put it prior to the rule that does the web/ rewrite. This allows you to change the protocol first then continue with your internal rewriting after the request returns on https.

    edit: More detail on HTTPS redirect: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

    打赏 评论

相关推荐 更多相似问题