Keep HTTP or HTTPS on .htaccess

亡梦爱人 提交于 2020-01-15 05:44:08

问题


I have the following .htaccess file:

RewriteEngine On 
RewriteCond %{REQUEST_URI} /api/profile/
RewriteRule ^(.*)$ http://whatsee-profile.s3.amazonaws.com/$1 [R,L]

It redirects my fake links to the real ones and works great! But I need to keep the original HTTP or HTTPS protocol before the url. I've tried the following, but it doesn't work.

RewriteEngine On 
RewriteCond %{REQUEST_URI} /api/profile/
RewriteRule (http|https):\/\/whatsee.plugapps.net\/api\/profile\/(.*) $1://whatsee-profile.s3.amazonaws.com/$2 [R,L]

Any idea what is wrong? Thanks for your help!


回答1:


It exists several ways of doing it.
Here is one working solution

RewriteEngine On

RewriteCond %{HTTPS} on
RewriteRule ^ - [env=protoc:https]
RewriteCond %{HTTPS} off
RewriteRule ^ - [env=protoc:http]

RewriteCond %{REQUEST_URI} /api/profile/
RewriteRule ^(.*)$ %{ENV:protoc}://whatsee-profile.s3.amazonaws.com/$1 [R,L]


来源:https://stackoverflow.com/questions/26222238/keep-http-or-https-on-htaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!