redirect to https folder in .htaccess - .htaccess

I was trying to get an entire directory/section of my website to automatically re-direct to https (secure) using the .htaccess file, so I found a solution on here. It turns out it re-directs my ENTIRE site to HTTPS except for the homepage. I'd like it to only re-direct the /php/ folder and anything inside it.
Thanks in advance for any help!
Here is my code in .htaccess:
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} php
RewriteRule ^(.*)$ https://beanstalkwebsolutions.com/$1 [R,L]

You can use this rule as your very first rule:
RewriteCond %{HTTPS} off
RewriteRule ^php(/|$) https://beanstalkwebsolutions.com%{REQUEST_URI} [NC,R,L]

Related

How to force https with .htaccess on pages with certain URL string

I've checked many posts related to this topic, but I they didn't work as I expected, so... this is my question:
I have several pages with this pattern in my website:
http://example.com/newsletter/[variable_substring]
And I need to force all of those urls that contain "/newsletter/" as a part of the url to use "https://" protocol instead "http://" (if they are accessed by http://, of course).
I need to do this in the .htaccess. Anybody knows what exactly I had to type in?
Regards,
Try to add this to .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^/newsletter/(.*)$ https://%1/newsletter/$1 [R=301,QSA,L]
Also in httpd.conf add AllowOverride All for this directory
Try the following code
RewriteEngine on
#if the https is off
RewriteCond %{HTTPS} ^off$
#and the request is /newsletter/...
RewriteCond %{REQUEST_URI} ^/newsletter/
#then redirect it to https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [NC,L,R]

mod_rewrite http/https for robots.txt

Is there a way to rewrite the path/filename for the robots.txt?
In my docroot, i placed robots.txt and a robots_ssl.txt. Now I want to "redirect" the bot, depending on which site he is actually visiting. I made a rule in my .htaccess which reads as followed:
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^robots\.txt$ robots_ssl.txt [L]
To see the diffrence, I added a comment on top of both of the files. When I'm calling https://example.com/robots.txt it should display a txt-file with the comment:
robots.txt for https
otherwise, in case of http:
robots.txt for http
Any ideas how to solve the problem? Is my RewriteCond wrong?
You can use this rule for serving a SSL specific robots.txt:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^robots\.txt$ robots_ssl.txt [L,NC]

How can I redirect a subdomain to a specific URL?

I am updating the Iirf.ini file to redirect sub.columbia.edu to giving.columbia.edu/video.
sub.columbia.edu is already redirecting to giving.columbia.edu.
How can I go one step further to redirect it to giving.columbia.edu/video.
Important Note: I would like the URL to show as sub.columbia.edu in the browser and not as giving.columbia.edu/video
#Redirect subdomain to specific URL
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^/$ /video
The above doesn't work. Any ideas how I should modify this?
Thank you!
You can try this and see how it works for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^(.*) http://giving.columbia.edu/video [L,R=301]
Or you can do a redirect, this should work also.
Redirect 301 / http://giving.columbia.edu/video

TYPO3 Force HTTPS in FE

I have two domains pointing to the same website, domain A and domain B. I want:
Domain A to be accessible via HTTP (works fine out of the box)
Domain B to redirect all requests to HTTPS. Basically if you type in http://domainb.com/somepage to redirect to http*s*://domainb.com/somepage. I would prefer to have this done via htaccess file.
I tried many solutions and I always get into redirection loop. Eg. I tried this:
RewriteCond %{SERVER_NAME} ^www\.domainb\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
....
rest of the standard typo3 htaccess commands.
My code was after typo3 be redirection part and before "Main URL rewriting" part in the htaccess file.
With code above I'm redirected to https but then "redirection loop" error is shown.
Any help is highly appreciated.
This works for me :)
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} domainb\.com$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I include this code right after this line with RewriteEngine On.
Try this:
RewriteRule ^http://www\.domainb\.com/(.*) https://www\.domainb\.com/$1 [R=301,L]
The only solution that worked for me was the following one:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

Subdomain Redirect

I want write a rule in .htaccess for redirecting
http://www.dir.domain.com
http://dir.domain.com
http://www.domain.com/dir
these should redirect to
http://domain.com/dir
Thanks in advance...
The trick here is to use an .htaccess file in your DOCROOT
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?dir\.domain\.com$
RewriteRule ^.* http://domain.com/dir/$0 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^dir/.* http://domain.com/$0 [R=301,L]
Note that this is doing a 301 redirect -- that is the server tells the browser that this is a permanent redirect and the browser caches this redirect.
You can also do an internal redirect where this mapping is done silently at the server end by tweaking flags.
This assumes that your shared service is using Apache, if its using IIS, then you need to do something similar with the web.config
You can try:
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$
RewriteRule ^ http://domain.com/%1 [L,NE]
Please change domain by your domain, when you enter sub1.domain.com then it will redirect to domain.com/sub1, when you enter sub2.domain.com then it will redirect to domain.com/sub2 ....

Resources