I've recently tried to force HTTPS on my website by using various directives contained in mod_rewrite. However it didn't workout very well and now it's recommented to use the Redirect directive from mod_alias. I've got everything in a subfolder and I wrote:
Redirect "/folder/" "https://mywebsite.org/folder/"
in my .htaccess file, but it keeps giving me the ERR_TOO_MANY_REDIRECTS error.
This code in .htaccess will redirect http://example.com to https://example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
I have a domain for which I would like to set up both a www and non-www redirect to https://newdomain.com.
So olddomain.com and www.olddomain.com should go to https://shinynewdomain.com.
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$
RewriteRule (.*) https://www.newdomain.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^olddomain\.com$
RewriteRule (.*) https://newdomain.com/$1 [R=301,L]
This is the code I'm using, and it sends me to a domain parking page at my registrar instead of the new domain at a different host.
Am I doing anything wrong?
There are several ways you can do the redirection of your old website to your new website. If your website is made using wordpress then it will be more easy to achieve 301 redirections.
Method 1:
In Wordpress, what you can do is install the plugin Simple 301 Redirect.
Setup the plugin as you like.
Then you will find options in Settings after activating it.
Method 2
Another is using some code line in the .htaccess file.
In the web directory settings, you will find the access of .htaccess file.
Open the file in the editor and use the code below.
To redirect a single page: Redirect 301 /old-file.html http://www.example.com/new-file.html
To redirect to a new website: Redirect 301 / http://www.new-example.com/
When I change my url from https://www.example.com/company/ to http://www.example.com/company/
I get redirected to the root page instead of it changing HTTP to HTTPS. What am I missing?
Here is my HTACCESS file, I am using a TYPO3 CMS 7.6.19
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The default .htaccess file for TYPO3 does some rewriting of its own. If you place this below at the bottom of that file, it will first execute the default rules. This will mess up your redirect. You should add these redirect rules above the default TYPO3 rewrite rules, so just below the existing RewriteEngine On.
This is how I am attempting to force www and HTTPS urls in htaccess right now.
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
The problem is that this still creates a redirect loop. It first redirects to https://example.com and then redirects to https://www.example.com
Is there a way to correctly write this in htaccess so that it redirects to both https and www at the same time eliminating the redirect loop?
I have tried many examples that I have found here on stackoverflow and they all render redirect loops. Is this unavoidable?
Thanks!
Does anyone have the setttings from the .htaccess file to remove www from my url?
http://example.com
I've tried using some of the settings in the internet but it gives me a redirect loop. I need something that prevents a redirect loop.
this would really help me. thank you
You can put this code in your htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you're still having a redirect loop:
you have maybe another script that redirects non-www to www
old rule still in browser's cache (try cleaning cache or with another browser)
I'm trying to redirect this URL to a different subdomain but am getting a 404.
Need to redirect:
www.dustystrings.com/instrumentbuilding / XYZ
To here:
manufacturing.dustystrings.com/instrumentbuilding / XYZ
I have www.dustystrings.com on one server, and manufacturing.dustystrings.com on another server (necessity).
Basically, I want to redirect all www.dustystrings.com/instrumentbuilding/ queries to manufacturing.dustystrings.com/instrumentbuilding/
What's the right .htacess 301 code to do this? (Apache server)
This should work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.dustystrings.com[nc]
RewriteRule ^.*/instrumentbuilding/(.*)$ http://manufacturing.dustystrings.com/instrumentbuilding/$1 [r=301,nc]
Redirect to www using htaccess redirect
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.