user2961763
user2961763

Reputation: 63

Htaccess redirect https and http and custom url

I am new to htaccess and even though I get the part to have a custom URL, I can't manage to figure out https redirect combined with having a custom URL. All the options I have found online have given me a redirect loop.

So, suppose I have a page called: mysite.com/hello.php and another one called mysite.com/bye.php.

I want mysite.com/hello.php to become mysite.com/one-hello and bye.php to become mysite.com/two-bye. This is how I have it in my htaccess now:

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^one-hello$ hello.php
RewriteRule ^two-bye$ bye.php

But now I want hello.php to always show up as https but bye.php to always show up as http. How could I write all of these?

Thanks!

Upvotes: 2

Views: 462

Answers (1)

anubhava
anubhava

Reputation: 785108

Have your rules like this:

RewriteRule ^one-hello$ hello.php [L]
RewriteRule ^two-bye$ bye.php [L]

RewriteCond %{HTTPS} off
RewriteRule ^hello\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R]

RewriteCond %{HTTPS} on
RewriteRule ^bye\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R]

Upvotes: 2

Related Questions