I'm currently trying to setup a website on free hosting, but use the "branded" URL registered with another provider. I've already tried switching NS but the free hosting NS is very restrictive (Doesn't allow TXT records).
I'm back with the URL registrar, and I've got a URL redirect to the "ugly" URL at free hosting. I've already tried to make the redirect masked, but I lose all the file names, and many meta tags due to the <iframe>. Also any files that aren't .html are served (e.g. sitemap.xml).
Is there anyway I can solve this using .htaccess on the free hosting side? - that's the only thing I have access to (i.e. no access to httpd)
I've tried all these "pairs" of rewrites but with no success (I'm still new at rewrites so they might not be completely correct)
#RewriteEngine On
#RewriteRule "^(.*)ugly.url.com(.*)$" "$1www.my-brand-url.com$2" [L,R=302]
#RewriteCond %{HTTP_HOST} ugly.url.com [NC]
#RewriteRule ^(.*)$ http://www.my-brand-url.com/$1 [L,R=302]
RewriteRule ^ugly.url.com/(.*)$ http://www.my-brand-url.com/$1 [L,R=302]
ServerName ugly.url.com
ServerAlias www.my-brand-url.com
Related
I have a problem with our site after reinstalling the SSL certificate, where the www version of the site (www.mountainx.com) pulls up a completely different site. if you enter the non-www version (mountainx.com), it goes to the correct website. Some of the rules in my .HTAccess file are here - Any help would be appreciated or at least I would like to get a discussion going -
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Also I have a certain number of proxy redirects that are not working either after the SSL change and I had to redirect them to the original hosts. To clarify, we use a third party to host our calendar but want to obscure the URL so it looks like we are still hosting the files. When the SSL certificate was installed, it suddenly started throwing up a 503 error so we agreed to change to the original URL hosted remotely. Also any good tutorials on .htaccess file out there? They seem to be pretty few and far between.
I have searched the site and thought I may have found code I could use for my issue, but it did not work.
I want to redirect my primary domain http to https (also including any form of url typed www. without www., http://www, http://, and even just the domain name without www or http before it), while Also not effecting my other domain that is sharing the same hosting within my primary directory (as the SSL I have only used for primary domain, but not used on other domains).
At current, I had code to make the redirect for my primary to https, but it would then make my other domain on same hosting account, also redirect to https.
Then I found code to not effect the other domain and not to redirect to https, but then it effected my primary domain to NOT redirect to https either, it would only redirect to https if with www. or http but would not redirect without the www.
This has been very frustrating because I am VERY new to attempting this type of code, so I don't have a clue what I am doing and could surely use the help. My Godaddy hosting would not help but give link to basic redirect code which does not help for other domains sharing hosting, nor did it work for typing domain without www etc. I hope this made sense.
Thank you in advance.
EDITED possible FIX:
Ok, my code might look a bit wonky and I'm sure it may need cleaning up and possible repetitive stuff removed, but this is what I just patched together from other code offerings I've found on this site, along with others I've found elsewhere and I think it might be working. I'm sure there is a cleaner way to format this, but at current it seems to be working.
# redirect http to https Domain
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} www.yoursite.com [OR,NC]
RewriteCond %{HTTP_HOST} yoursite.com
RewriteRule (.*) https://yoursite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.yoursite\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
My very dear Stackoverflow community,
I have the following redirection problem and after several unsuccessful attempts I come here in search of enlightenment. My problem is the following. I have a domain, let's call it 'www.mydomain.com', and my 'public_html' directory has two folders as follows:
public_html
public_html/my_app/
public_html/my_other_app/
First, I would like that when typing the URL 'www.mydomain.com', I get redirected to the contents of folder 'my_app', while keeping the same URL. In fact this I have already accomplished, so whenever I type 'www.mydomain.com' I get redirected to 'www.mydomain.com/index.php', which actually corresponds to the 'public_html/myapp/index.php' script under 'myapp'.
Now I want to have a subdomain called 'other.mydomain.com', which has to redirect to contents of the 'my_other_app' folder, but I do not know how to make .htaccess work for this and at the same time work for the first case also.
So this is basically, the main domain redirects to one folder, and a subdomain redirects to another folder, and both folders are located under the public_html directory
Any hints more than welcome.
For your reference I post below my current .htaccess file:
RewriteEngine On
# redirect to www prefix
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
# if start with www and no https then redirect
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
# rewrite URL to trim folder
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^$ /login [L,R=301]
RewriteRule ^(.*)$ test/$1 [L]
This actually works for my main domain, it also rewrites the url to https. I need to add something in here in order to process separately the 'other.mydomain.com' and redirect to the '/my_other_app/' subfolder
what you need is a vhost (virtual host) per app. In the vhost, you will define the vhosts root directory, which will point to either of your sub directories.
There is IP based vhosts (one IP address per subdomain) or name based vhosts (the vhost is chosen based on the HTTP host header that all modern browser send).
But there is too much to say about vhosts to write it all here, just read the apache documentation here:
http://httpd.apache.org/docs/2.2/vhosts/
I think with pure .htaccess files, you can't do that (I might be wrong). Normally you would add vhosts in the main apache config. Based on your hosting, this may not be possible. Talk to you hosting provider in that case.
Marc
I am trying to force HTTPS on a domain. It must be done using a method that works by domain name and not port number (due to host structure/setup).
My closest attempt was:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^.*$ https://www.mydomain.com/$1 [R=301,L]
This works when typing "mydomain.com" into the address bar, automatically redirecting to "https://mydomain.com" but when I type "www.mydomain.com" it does not work. I assume it is a syntax issue as I am very new to htaccess and have spent about 4 hours trying to create a solution from other's code.
Any chance of a pointer?
To make the setup a little more understandable.
/public_html/ - All files in this folder relate to www.mydomain.com
/public_html/subfolder - These folders contain files also relating to mydomain.com
/public_html/subdomain - These folders contain files relating to www.myotherdomain.com
My other domains are subdomains of mydomain.com for to be listed in the cpanel on the host. For example: subdomain.mydomain.com is the same as www.myotherdomain.com.
Hopefully that clears up the structure.
Your redirect happens whenever a request is made to the exact domain mydomain.com (that's what the RewriteCond is testing for). It doesn't apply to any other domains and doesn't detect HTTPS. Use this instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
I'm moving my site to a new host but I need to have my current server continue to handle requests (not all files can be moved to the new server).
So I added a parked domain to my old server (old.mydomain.com) and I want all requests to it to be written to the files from the old site.
My old site (mydomain.com) was hosted internally in a folder (/public_html/mydomain/) and I want all requests to old.mydomain.com to be rewritten to the same folder.
So if mydomain.com/blog was internally at /public_html/mydomain/blog, I now want old.mydomain.com/blog also to reach /public_html/mydomain/blog.
Here is the .htaccess that I'm trying to use:
RewriteCond %{HTTP_HOST} ^old\.mydomain\.com/*
RewriteRule ^(.*)$ mydomain/$1 [NC,L]
But for some reason as soon as I add the $1 in the rewrite rule I get an internal error.
Any ideas?
Configure this as a separate vhost called old.mydomain.com and ensure it comes before *.mydomain.com in your vhost definitions (i.e. higher in vhosts.conf). Give old.mydomain.com the same DocumentRoot as your previous domain had.
.htaccess is the most processor intensive way to serve a webpage, and should only be used there are no other options available.
Please try to fix your .htaccess config as follows:
RewriteCond %{HTTP_HOST} ^old\.mydomain\.com$
RewriteRule ^(.*)$ /public_html/mydomain/$1 [NC,L]