: How to setup up .htaccess rewrites for http and https on the same site? I'm having some issues with htaccess rewrites i need to redirect different parts of my site to HTTPS rather than HTTP,
I'm having some issues with htaccess rewrites i need to redirect different parts of my site to HTTPS rather than HTTP, for example login and news sections. I'm not sure how to go about doing this in the correct manner.
So at the moment I have
RewriteRule ^login/?$ index.php?p=login [R,L]
I would like to redirect this to HTTPS, I have tried the following:
RewriteRule ^login/?$ %{SERVER_NAME}/index.php?p=login [R,L]
but it doesn't seem to work. Am I missing something? I have rewrite on and all other settings as they work.
Also is there anyway to get htaccess to use a different set of rules if HTTPS is set to when it is not?
Update:
So what I want to do is rewrite www.site.tld/login/ rewrite to www.site.tld/login/code and then further rewrite to www.site.tld/index.php?p=login. So the user sees: www.site.tld/login/ but it is actually doing www.site.tld/index.php?p=login
More posts by @Karen161
2 Comments
Sorted by latest first Latest Oldest Best
First, redirect /login to https /login/code
RewriteRule ^login/?$ %{HTTP_HOST}/login/code [R=301,L]
You can also force /login/code to redirect to https in case the type in http /login/code:
RewriteCond %{HTTPS} ^off$
RewriteRule ^login/code$ %{HTTP_HOST}/login/code [R=301,L]
Then, you can rewrite /login/code
RewriteRule ^login/code$ /index.php?p=login [R,L]
Not sure how to do it all with re-writes. I have the following in the header of my php files:
if( $_SERVER['SERVER_PORT'] == 80 && $_SERVER['HTTP_HOST']!="localhost")
{
header('Location: '.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); }
And then this in my .htaccess
#re -write /login/username to /login.htm?login=username
RewriteRule ^/?login/([^/.]+)/?$ /login.htm?login= [NC,L] #re -write /login and /login/ account-login.htm
RewriteRule ^/?login/?$ /account-login.htm [NC,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.