Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep HTTP or HTTPS on .htaccess

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!

like image 209
bodruk Avatar asked Jan 25 '26 18:01

bodruk


1 Answers

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]
like image 59
Justin Iurman Avatar answered Jan 29 '26 12:01

Justin Iurman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!