So I have been searching the net along with this site regarding htaccess redirections, but have yet not managed to find the solution for myself (it may not even be possible).
So my scenario is this:
I have bought a cheap host, which comes with a subdomain, but also has the ability to add your own domain as an alias to it. Right now I can access the site using:
subdomain.hostprovider.com
and
mydomainasalias.com
What I wish to achieve here, is that I would be able to redirect a subdomain from the domain alias to a random page on a random site.
So
subdomain.mydomainasalias.com
is basically
2ndsubdomain.subdomain.hostprovider.com
I have tried this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomainasalias\.com$ [NC]
RewriteRule ^ http://randomsite.com/asd [L,R]
amongst some other things, to achieve this, but have yet not succeeded. Is it even possible?
Related
I want to buy a new domain, and have it redirect all page requests, to another domain (example.com).
So if someone goes to newexample.com/page-1, he will get a 301/302 redirect to example.com/page-1
If I do this with htaccess, it means I need to buy hosting first, but maybe that's not necessary and I can do with some kind of DNS definitions?
If it would be with htaccess, Should it look something like this?:
###
RewriteCond %{HTTP_HOST} ^\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R=301]
###
I think a proxy server (eg. Nginx, HAProxy) will be a better option for this use case.
A client of mine has found out today that someone has set up a spoof domain (1 letter different - design instead of designs) and has tried to set up credit accounts in his name.
The domain will undoubtedly be removed, but is it possible in the meantime using some htaccess trick to check if a visitor to www.designs.com has been referred from www.design.com and if they have, send them to a warning page?
You can use this code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http(s)?://([^\.]+\.)?design\.com
RewriteRule ^.* /warning.html [L,R=302]
It will redirect any pages coming from design.com and its possible subdomains (using http or https) to a page named warning.html at the root of your project.
You can test this rule with this online tool.
I have a Joomla site mysite.com.
I want to have the subpage mysite.com/example act like a separate website using a separate domain name anothersite.com.
Can this be achieved using DNS settings on the domain and htaccess?
Hosting sites at cloudaccess.net but want this solution for one-page sites and landing pages without using a whole other hosting account / joomla instance.
Thanks.
If your hosting provider allows you to have "alias" domains, you can point the new domain at the existing code, and detect the hostname using RewriteCond:
Start by configuring the new domain to display all the same content as the existing domain.
In the Apache configuration (probably .htaccess on shared hosting) add a rule which detects requests for the new domain, and "rewrites" them to instead serve your specific page:
RewriteCond %{HTTP_HOST} landingpage.example.com
RewriteRule ^/$ /url/for/my/landing/page
Add an additional rule afterwards so that other URLs on that domain redirect the browser back to the main site
RewriteCond %{HTTP_HOST} landingpage.example.com
RewriteRule ^/([^/].*)$ http://realsite.example.com/$1 [R=permanent,L]
A variation of this would be to map everything on the second domain to a directory (or, rather, a URL prefix) in the first domain, by combining those two rules:
RewriteCond %{HTTP_HOST} subsite.example.com
RewriteRule ^/(.*)$ /url/for/my/subsite/$1 [L]
Note: If Joomla thinks it knows the "correct" URL for the page, it may try to redirect away from your new domain. If so, that is the topic for a new question.
If, on the other hand, you want to use Apache configuration to force users accessing http://realsite.example.com/url/for/my/landing/page to be redirected to http://landingpage.example.com/, you could add something like this:
RewriteRule ^/url/for/my/landing/page$ http://landingpage.example.com/ [L,R=permanent]
Note: Depending on some environment settings I don't fully understand, you may need to change ^/ to just ^ in the patterns above.
Plesk offers you a handy way to preview the site before you switch over the DNS, called Websites Preview.
This is what it does:
customer-site.tld will be available for preview as customer-site.tld.192-0-2-12.your-domain.tld. Here 192-0-2-12 is the site's IP where dots are replaced with dashes
I find this feature very useful, as we use it for proofing websites before they go live, however after the site goes live the customer-site.tld.192-0-2-12.your-domain.tld URL still exists, and is showing up in some Google results!
How can I remove the preview URL for certain sites only, not for all sites on the server?
Alternatively I think I may be able to use a .htaccess rule for this, but I cannot figure out how to do that without a redirect loop.
I found the answer to this with some more searching (I searched for how to redirect domain alias, as that's what this essentially is).
The answer is here: Redirecting all domain aliases to one with htaccess
RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
Use robots.txt file to prevent crawlers from indexing your page. After you have done DNS switching, remove robots.txt file
I have two working domains on the same server.
How can I forward all traffic to all files on the old temporary domain to the new correct domain?
Seems like this might be an SEO issue?
But, since the temporary testing domain isn't registered, would it even be crawled?
Is this even a problem?
I'm currently using:
RewriteEngine On
# Force to WWW
RewriteCond %{HTTP_HOST} ^thecorrectdomain\.com
RewriteRule (.*) http://www.thecorrectdomain.com/$1 [R=301,L]
#
The incorrect domain is the setup that we used for testing, before we pointed the domain name to the new server.
The second is the correct domain.
The incorrect testing domain looks like:
http://1234.hostingcompany.com/~username/index.php
The intended correct domain looks like:
http://thecorrectdomain.com/index.php
Or is this something that the hosting company has to do at their level?
Assuming hostingcompany supports .htaccess. You create a .htaccess in http://1234.hostingcompany.com/~username/ which contains something like:
RewriteEngine On
#might not be necessary
RewriteBase /~username
RewriteRule .* http://thecorrectdomain.com/$0 [R=301]
PS while testing use 302, instead of 301.