. htaccess-使用HTTPS重定向到子文件夹,同时隐藏URL部分 [英] . htaccess - redirect to subfolder with HTTPS while hiding URL part

查看:90
本文介绍了. htaccess-使用HTTPS重定向到子文件夹,同时隐藏URL部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将整个网站重定向到https://,同时隐藏部分URL.

I am trying to redirect an entire website to https:// while hiding part of the URL.

我的根看起来像这样:

/mywebsite
    /subfolder_1
    /subfolder_2
    /subfolder_3
    ............

到目前为止,我设法隐藏了URL部分以及文件扩展名:

So far I managed to hide the URL part as well as the file extensions:

Options +MultiViews
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^mywebsite\.com$
RewriteCond %{REQUEST_URI} !subfolder_1/*
RewriteRule (.*) /subfolder_1/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

但是在将URL部分隐藏的同时,我在重定向到HTTPS时遇到了问题.

I am however having problems redirecting to HTTPS while keeping the URL part hidden.

我尝试了

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]

但是,如果使用此选项,所有其他更改似乎将不适用,从而使整个URL可见(mywebsite.com/subfolder_1/index.php而不是mywebsite.com/index.php).

but it seems if I use this all the other changes will not apply, making the entire URL visible (mywebsite.com/subfolder_1/index.php instead of mywebsite.com/index.php).

有什么想法吗?我已经尝试了一段时间,似乎无法找到合适的解决方案.

Any ideas? I've been trying for some time now and it seems I am unable to find a proper solution.

推荐答案

您可以使用以下规则:

Options +MultiViews
RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_URI} !/subfolder_1/ [NC]
RewriteRule .* /subfolder_1/$0 [L]

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

这篇关于. htaccess-使用HTTPS重定向到子文件夹,同时隐藏URL部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆