HTTP to HTTPS (And redirection to other website)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect 301 / https://www.tiktok.com/@imboredaware

Hold on, I mistyped before, there should be two htaccess files, on in htdocs and one in the root.

Can you share the full contents of both of them?

3 Likes

It’s a long discussion, if you wanted that whenever someone types http://example.com or example.com, they should be taken to https://example.com.
Here’s code:

DirectoryIndex index.php index.html index.htm index2.html

ErrorDocument 400 https://bluewinds.rf.gd/e/400.html
ErrorDocument 401 https://bluewinds.rf.gd/e/401.html
ErrorDocument 403 https://bluewinds.rf.gd/e/403.html
ErrorDocument 404 https://bluewinds.rf.gd/e/404.html
ErrorDocument 503 https://bluewinds.rf.gd/e/503.html

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:CF-Visitor} !{"scheme":"https"}
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Delete htaccess from root. Create new one inside htdocs/, paste the code.
Remember to change error pages to your own.
https://example.com/err/404.html

1 Like

I don’t know if it’s because you’ve changed something, but your site already works the way you want it to. It just isn’t seen by the naked eye because, immediately after redirecting visitors to the HTTPS version, it redirects them to TikTok as you intended it to.

You can see what I mean by using a tool that traces redirects, such as the one I used.

2 Likes

I just stopped using infinityfree.

This thread can be closed.

Just FYI: our own redirects tool only shows http:// as prefix in the list, but it also redirects https://, http://www. and https://www..

I’m not entirely sure where and how you got the “not secure” error, but I can tell you that if you want to redirect a website over HTTPS, the source domain also needs to support HTTPS, i.e. have a valid SSL certificate.

And both redirecting an entire site and setting up forced HTTPS is unnecessary. It really doesn’t matter if you redirect from http://example.com to https://example.com to https://other-site.example.net, or straight from http://example.com to https://other-site.example.net. The first option just slows things down for no reason.

8 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.