RewriteCond %{REQUEST_URI} !/(market|other|available|areas)/ [NC]
RewriteRule ^(.*)$ /market/$1 [R=301,L]
As you can see, I currently have my htaccess setup so that any page that tries to be accessed but does not exist, will resort back to /market/, along with going to the original domain example.com, will redirect to example.com/market/ while the other designated directories are also still available.
My simple question is, if I activate an SSL on my account, would there be anything to change with this? or does this not listen to http or https but simply the directory redirects?
Thanks!
-- EDIT --
As I kind of suspected, the original rewrite didn't pay attention to the http/https (thank you Panama Jack). Would this solution work? as it first checks to goto https, and then will send off to the /market/ directory?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !/(market|other|available|areas)/ [NC]
RewriteRule ^(.*)$ /market/$1 [R=301,L]
Related
this is kinda an odd one:
I need my site to do two things (one of which is already working):
if a user tried to access the domain via HTTP:// it is replaced with https:// - this is for SEO in google and to make the user feel more secure -
the site folder that is used to load the website needs to be the subdomain folder of the site
Oddly the second part of this is working and I figured out - however I'm not sure how to merge these two requests:
HTACCSESS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^trippy\.co\.nz$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.trippy\.co\.nz$
RewriteCond %{REQUEST_URI} !update.trippy.co.nz/
RewriteRule (.*) /update.trippy.co.nz/$1 [L]
But I'm not sure how to make the site display as
https://trippy.co.nz/
I have tried:
RewriteEngine On
RewriteCond %{HTTP_HOST} update\.trippy\.co\.nz [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://update.trippy.co.nz/$1 [R,L]
but then the web address displays as: https://update.trippy.co.nz
and I need to remain as https://trippy.co.nz/
Any help here would really great and I know its a odd situation to be in.
THanks,
Wally
...but then the web address displays as: https://update.trippy.co.nz
You would seem to be redirecting to the subdomain itself, not the subdomain's subdirectory, as you appear to be doing in the first rule. You may also be putting the directives in the wrong order - the external redirect needs to go first - otherwise you are going to expose the subdomain's subdirectory, which does not appear to be the intention.
Try the following instead:
RewriteEngine On
# Redirect HTTP to HTTPS
RewriteCond %{HTTP_HOST} ^(www\.)?trippy\.co\.nz [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L]
# Rewrite all requests to the subdomain's subdirectory
RewriteCond %{HTTP_HOST} ^(www\.)?trippy\.co\.nz [NC]
RewriteRule !^update\.trippy\.co\.nz/ /update.trippy.co.nz%{REQUEST_URI} [L]
No need for the extra condition in the 2nd rule block, as the check can be performed directly in the RewriteRule and use the REQUEST_URI server variable instead of the $1 backreference in the substitution string.
That that R by itself is a temporary (302) redirect. You may want to change that to R=301 (permanent) once you have confirmed this is working OK.
My host automatically sets up subdomains for all our hosted websites. So that zzz-thewebsite.myhosting.com is the same files as www.thewebsite.com ...
Unfortunately, somehow google has indexed the subdomains and now I probably have duplicate content.
I'd like to remove the subdomains from the index. I'm not sure the best way to do it.
I was thinking a .htaccess file that redirects zzz-thewebsite.myhosting.com to www.thewebsite.com would probably do the trick. Of course, there are subfolders involved as well.
Is there an elegant solution for this? I suppose a robots.txt might also do it but that will be in the both the zzz-thewebsite.myhosting.com and www.thewebsite.com "sites" since they are the same physical folder on the hosting.
Thank you.
Ben's answer below works great for me on non https sites but is not working for an https site. What I am using is this:
#attempt to redirect subdomain
RewriteCond %{HTTP_HOST} ^thewebsite-zzz.myhosting.com$ [NC]
RewriteRule ^(.*)$ https://www.thewebsite.com%{REQUEST_URI} [R=301,NC,L,QSA]
#https only
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#www only
RewriteCond %{HTTP_HOST} ^thewebsite.com [NC]
RewriteRule ^(.*)$ https://www.thewebsite.com/$1 [L,R=301,NC]
Setting up a permanent redirect is a preferred way.
RewriteCond %{HTTP_HOST} ^zzz-thewebsite.myhosting.com$ [NC]
RewriteRule ^(.*)$ https://www.thewebsite.com%{REQUEST_URI} [R=301,NC,L,QSA]
Say I have the site blog.mydomain.com and www.mydomain.com. I want to make sure that if people type in blog.mydomain.com, that it'll redirect to www.mydomain.com/blog.
(I know the question is usually asked the other way around..)
I found and edited the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/blog/$1 [R=301,L]
Is this correct?
And: Do I need to create a record in my DNS to make the subdomain? (since this .htaccess stuff is on the regular domain of course and not on the blog.mydomain.com..)
This should do the trick
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com
RewriteRule ^(.*)$ http://mydomain.com/blog/$1 [R=301]
I have forced a ecommerce site to be always in https, due to some issues with having only specific urls triggered as secure. I have used the following in my .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.vshoen.com/$1 [R,L]
But now my problem is all external links without www in the url open in https as well for some reason. Most of the time its not a problem but there are a few specific links that need to simply be http://url.com instead of http://www.url.com and for in this case they are not loading as its trying to open them as https://url.com
I was hoping there would be a resolution to this, this is a wordpress site if that makes any difference.
Thanks in advance.
Try this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
I'm sure there is an easy answer to this question, but I've scoured through through available threads and its either not there or I'm too ignorant to recognize it starting in my face. This seems to be the answer, but I just can't configure correctly.
Question: How do I set up .htaccess so that all subdomains are forwarded to their https equivalents, while also allowing the main domain itself get ported to its https equivalent? In other words:
hxxp://subdomain1.domain.com --> hxxps://subdomain1.domain.com
hxxp://subdomain2.domain.com --> hxxps://subdomain2.domain.com
...and so on, but also...
hxxp://domain.com --> hxxps://domain.com
Current Configuration:
My .htaccess is set up to provide an unconditional forward as follows:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
To achieve what I want, I would think that there must be some way to define a wildcard and pass the result of that wildcard as the subdomain - whether, subdomain1, subdomain2 or a value of nothing - to the actual redirect.
Any help would be much appreciated.
I haven't tested this, but it should allow you to capture the subdomain as well as the request.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.*)\.yourdomain\.com$
RewriteRule ^(.*)$ https://%1.domain.com/$1 [R,L]
This rule however, will not work for requests that do not contain a subdirectory, so you actually need two rules.
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
Goto your subdomain folder
Create .htaccess file in this folder
and paste this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]