Confused over setting up Sub Domain / Alias as a forwarder to location on apache server - apache

I am a little confused over the correct method to redirect/forward a domain alias (sub domain) to a directory on my website using apache.
I want the following domains http://helpdesk.xxxx.com and https://helpdesk.xxxx.com to redirect to https://www.xxxx.com/helpdesk.
I don't have a wildcard SSL cert so I am not sure if using rewrite would be the best method, I just want the server to forward any requests to those Alias on ports 443/80 to correct patch on the server.
Thanks

You can have this rule in root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(helpdesk)\.(.+)$ [NC]
RewriteRule ^ https://www.%2/%1%{REQUEST_URI} [L,R=301,NE]

Related

Issues redirecting from old HTTPS domain to new HTTPS domain via htaccess?

I have tried a zillion variations of .htaccess rewrites and cannot get this to work.
I have a previous HTTPS old-domain.com that I need to forward to new-domain.io. Both are HTTPS but only the new domain has SSL certs on the server. This makes the browser trying to load old-domain.com just spin in the browser.
I already have a DNS forward that works fine ONLY with http, not https. I am thinking that I need to use something like %{HTTP:X-Forwarded-Proto} but not exactly sure how. Nothing has worked so far.
https://old-domain.com
AND https://www.old-domain.com
both need to redirect to https://new-domain.io (along with any URI like/something/this.html)
Something like this looks like it should work, but redirects infinitely.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
RewriteRule (.*)$ https://new-domain.io/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*)$ https://new-domain.io/$1 [R=301,L]
SOLUTION --------
The new domain .htaccess file cannot fix a HTTPS redirected link by itself.
There are two ways to correctly fix it.
Remove DNS forwarding at the old domain DNS. Then make sure there are still valid SSL certs AND put a redirect on its .htaccess file to handle the redirects with something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} (w*)domain.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
Leave the DNS forwarding of the old domain and add a new multi-domain SSL cert at the new domain which includes BOTH domains. This is tricky because you will have to manually authenticate the old domain because the cert won't be living at the old domain host.
I choose and implemented #1 successfully.

Https Domain Redirection Guide

I am facing an issue with the domain redirection.
I am trying to redirect my old domain to another new one, so the current domain is for example https://example.com and the new one is https://exampleapple.com the old is using SSL and I implement SSL on the new too, the old domain redirects fine without SSL (http) but is not redirecting on (https).
Can anyone please guide me as how this works?
You can easily do that with .htaccess file. There is no need to use GoDaddy's functionality. Just add these lines to the .htaccess file in the directory of your example.com domain on your server :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/exampleapple\.com\/" [R=301,L]

Apache virtual hosting url redirect from one domain to other domain without showing the url in the browser

Apache virtual hosting url redirect from one domain to other domain without showing the url in the browser?
That's not redirect, that's called Reverse Proxy.
Example:
ProxyPass /url-path/ http://backend.example.com/url-path/
This will reverse proxy all requests to /url-path/whatever to the server backend specified
More information at:
http://httpd.apache.org/docs/2.4/mod/mod_proxy.html
http://httpd.apache.org/docs/2.4/howto/reverse_proxy.html
No, there isn't a way to do this with .htaccess if your sites are on different servers. Doing so would present big security hole, imagine if someone does this with a bankĀ“s website.
However, if both are hosted on the same server try this on your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^http://www.domain1.com$
RewriteRule (.*)$ http://www.domain2.com$1 [P]
</IfModule>
If you own both domains you could accomplish this with domain name forwarding. Check the options in your registrar (maybe godaddy, or dns managers like cloudflare).

htaccess www sub domain redirect

My problem
I have a sub domain pointing to a different server. The server has a SSL, thus when a user types in the sub domain: https://my.maindomain.co it works great. Using htaccess I'm trying to redirect all users who type in the following web address: https://www.my.maindomain.co or the http:// equivalent to the correct version (https://my.maindomain.co).
I thought the below would work nicely but it does not:
# rule for removing www on sub domains
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.maindomain\.co)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
Anybody help me out with this?
For reference I am placing this code in the htaccess on the maindomain.co server, which is hosted on a different server to my.maindomain.co
You can use this rule for your subdomain on the server where the sub domain is hosted. It should take care of your requirements.
RewriteEngine On
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^my\.example\.co$ [NC]
RewriteRule ^ https://my.example.co%{REQUEST_URI} [R=301,L]
Note you must have a valid ssl certificate for www.my.example.co for this to work if they enter www.my.example.co. Otherwise it will still handle redirecting http://my.example.co to https://my.example.co.
First of all what do you mean by 'it does not work'? It would be helpful, if you could specify what is the exact error you get when you try to load https://www.my.subdomain.co
Apart from that i can think of one more factor, if you are using apache server, u might want to add 'www.my.tutella.co' to ServerAlias under virtual host configuration of my.tutella.co
You don't actually need mod_rewrite to do this.
In the .htaccess of your subdomain (or, if you have access to the main Apache configuration, that's more efficient than .htaccess files) you can use this directive:
Redirect / https://my.example.co/
...this uses mod_alias and is much easier to understand and troubleshoot than the mod_rewrite equivalents.

How to add a rewrite rule for domain and it's subdomains in Plesk 11.0.9?

I need to redirect a request file from all possible subdomains to one file which is located in top level domain:
^.example.com/robots.txt >> http://example.com/robots.txt
The robots.txt may or may not exist in the subdomain httpdocs, this rule must be exucuted first (we want to block all crawlers in advance).
The folder structure provided by Plesk 11.0.9 is:
example.com/
...
httpdocs/
subdomains/
sub1/
httpdocs/
example.com is owned by root.
Where can I add an apache rewrite rule that would be trigger for all subdomains?
Edit: I tested with ping doesntexist.example.com and the request does get directed to example.com which means teoretically there should be a point in processing to execute the rewrite logic.
Try placing this rule in /example.com/httpdocs/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)[^.]+\.(example\.com)$ [NC]
RewriteRule ^robots\.txt$ http://%1/$0 [L,R=302,NC]