I need all my domains to have the https certificate, but when I created the .htaccess file, the website wen't down.
Here's the story:
I have a Ruby on Rails website let's call: web1.com.br
I also have the domains: web1.com, web2.com.br and web2.com
I made the DNS mapping so whenever people type those 3 domains, they all go to my original host on web1.com.br (and not changing the url for the user) and it works fine.
But I don't have my https certificate when someone types the other 3 domains. Only on my original website web1.com.br I have the let's encrypt certificate
I asked my host provider for help and they told me to add to my www folder a .htaccess file but I probably did something wrong.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web1\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.com.br.
RewriteRule ^ http://www.web1.com.br%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^web2\.com\.br$ [OR]
RewriteCond %{HTTP_HOST} ^www\.web2\.com\.br$
RewriteRule ^$ http\:\/\/www\.web1\.com\.br\/ [R=301,L]
I created the .htaccess file and my website (on all domains) went off, giving a 500 response:
"The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at web#web1.com.br to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."
I deleted the file and the site went back online
As you can probably tell, I'm a total noob but can't find someone to help me. I don't know if I did the .htaccess wrong or my hosting support gave me the wrong information.
Thank you
Check this rules in your .htaccess file, redirect all to https://web1.com.br/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?web1\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?web2\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^web1\.com\.br [NC]
RewriteRule (.*) https://web1.com.br/$1 [R=301,L]
Related
I try to force a user which is coming via a specific domain example-page.com to always get redirected to /countdown
My approach was the the following:
RewriteCond %{HTTP_HOST} ^example-page\.com [NC, OR]
RewriteCond %{HTTP_HOST} ^www.example-page\.com [NC]
RewriteCond %{REQUEST_URI} !^/countdown
RewriteRule ^(.*)$ https://www.example-page.com/countdown [L,R=301]
But for some reason I always get a "Too many redirects error".
I get redirected to the https://www.example-page.com/countdown but somehow the RewriteCond is triggered again but it should not because of the RewriteCond %{REQUEST_URI} !^/countdown.
You may try this rule:
RewriteCond %{HTTP_HOST} ^(?:www\.)?example-page\.com [NC]
RewriteCond %{THE_REQUEST} !\s/countdown [NC]
RewriteRule ^ https://www.example-page.com/countdown [L,R=301]
Make sure to test if after clearing your browser cache.
Could you please try following, with your shown samples. Please keep these Rules at top of your htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?example-page\.com [NC]
RewriteCond %{REQUEST_URI} !^/countdown
RewriteRule ^ https://www.example-page.com/countdown [L,R=301]
Also why you are getting error because you have space between NC and OR(NC, OR) which is causing that 500 internal error.
I know my question is asked many times but unfortunately I could't find my answer. Maybe because I don't put the .htaccess file in the correct place.
What I want is to redirect http://mail.example.com , https://mail.example.com to https://example.com.
I also wanted to redirect https://www.example.com , http://example.com, http://www.example.com to https://example.com. I did this job with adding below code in .htaccees file in public_html in cpanel and it works.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
I used below code from this link and put .htaccess file in mail folder. but when I type http://mail.example.com it redirects to https://mail.example.com and https://mail.example.com also doesn't go to http://example.com. Maybe the problem is with https.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail\.mysit\.com [NC]
RewriteRule ^(.*) https://example.com/$1 [L,R=301]
Any help is appreciated.
p.s. My site is designed with joomla and there is no redirection in cpanel and joomla settings.
I think everything is correct, and that 'it's only a matter of order:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail\.example\.com [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
In you main .htaccess file
I have a https website which has a hidden user area. From there the users has a link which links to a http site. With a referrer the site makes sure that the userers are coming from my site. Other access attemps are blocked.
Since my webstie change to https, there referrer is not working anymore.
My solution attempt so far:
Inside my htaccess I want to stop the https for only one file on the site. Where the link is. My htaccess so far.
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/Mitgliederservice/Infoline/index\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I don't understand whether you want to exclude one page or force only one page to https so , if you want to exclude one specific page use the following code :
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/path/to/yourpage\.php$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
otherwise use the following code :
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/path/to/yourpage\.php$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
So the problem I am currently having is that our entire website is indexed using https. we want to redirect to http using .htaccess. the problem is that we need a couple of URIs to still use https and I am not sure how to write the exception for URIs
I know the below example would work if our site functioned like this www.example.com/account.php but our site urls are like www.example.com/index.php?l=account
# Turn SSL on for account
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
how can i fix this, any guidance would be appreciated.
thanks
EDIT!
So this code below I have working but I would like to make one more exception that I cant seem to get to work, I also want the root (index.php) to only use http.
I tried using...
RewriteCond %{REQUEST_URI} !^/index.php
but this did not work
# invoke rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{https} off
RewriteCond %{QUERY_STRING} !^l=product_detail
RewriteCond %{QUERY_STRING} !^l=product_list
RewriteCond %{QUERY_STRING} !^l=page_view
RewriteRule ^(.*)$ https://%{HTTP_HOST}/development/$1 [R=301,L]
thanks
Try
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/account.php
RewriteCond %{QUERY_STRING} !^l=account
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/account.php [OR]
RewriteCond %{QUERY_STRING} ^l=account
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I think that I have configured ok the wildcards in my domain, because it works to me:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.*)$ http://www.example.com/member.php?username=%1 [R,L]
But only if I redirect with R or R=301 flag. I would like to have a virtual subdomain, and the user don't notice it. subdomain.example.com and don't change the url in the bar.
I have tried the next:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.*)$ http://www.example.com/member.php?username=%1 [L]
Without the R flag. But I get an Internal Server Error. What is the problem? Could someone help me please?
You can't redirect to a absolute url without redirect.
"Virtual user host" section in this document solves your problem.
If you user.example.com and www.example.com are pointing to same machine then
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).example.com
RewriteRule ^(.*)$ /member.php?username=%1 [L]
But what are you planning to do with group captured in RewriteRule