Can I use htaccess to invisibly redirect one domain to a subdomain on another domain? - apache

I've been pulling my hair out trying to research this and find out if this is possible. Any help would be appreciated.
I have two domains. Let's call them foo.com and bar.com. I only have one web server, so right now, they're pointing to the same place.
I have a separate site set up at bar.foo.com.
I want all visits to bar.com to go to bar.foo.com, but still say "bar.com" in the browser's address bar.
Here's what I've got in my htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bar.com$ [NC]
RewriteRule ^(.*)$ http://foo.bar.com/$1 [R=301,L]
This successfully redirects it, but, you end up seeing "foo.bar.com" in the address bar.
Using htaccess, can I get this redirect to happen "invisibly", so that if the user types in "bar.com", they will still see "bar.com" in the browser?
I don't have access to the apache config files on the server, so I'm limited to what I can put in a htaccess file.
Any help or advice would be much appreciated.
Thanks!

Related

Redirect www.sub.domain.com to sub.domain.com

I realize this has been discussed before here.
But I didn't really get the information I needed from the answers there.
I have a subdomain on sub.domain.com, now I have some people trying to access it using www.sub.domain.com, which is obviously a problem. I need to redirect people trying to use www. to sub.domain.com
I don't have much knowledge with .htaccess or A(Host)/CName but if someone can tell me exactly what records I need to add and what it needs to point to that would help alot.
First, you need to add DNS records (either CNAME or A) for www.sub under the domain.com domain, to point to the same place as sub. This will make it so when someone goes to www.sub.domain.com, they go to the same IP address as sub.domain.com.
Second, you need to add this rule to the htaccess file in your webserver's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]

Point domain A to single page of Joomla site with different domain B, but keep Domain A as url

I've looked at a couple different questions on here that looked like they might answer my issue, (like: Domain to point to a single page) but not quite. They've gotten me close, but this is still not working for me, and I think the issue is likely how Joomla creates the SEF urls.
I have a Joomla site "mainsite.com" (for example) and I have a new domain "quiz.com" (for example). I would like to have a masked redirect where new domain quiz.com points to a Joomla page I have off the mainsite - mainsite.com/quiz, yet keep quiz.com as the address. So quiz.com = mainsite.com/quiz, but the domain quiz.com stays in the url bar.
So in CPanel, I added the new site quiz.com as an addon domain. It also created a directory for it under public_html/quiz.com
In that directory, I have this in the .htacess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^quiz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.quiz\.com$
RewriteRule ^/?$ "http\:\/\/mainsite\.com\/quiz\/" [R=301,L]
What is happening is when I bring up quiz.com, it actually brings up quiz.com/cgi-sys/defaultwebpage.cgi ?? There isn't even a cgi-sys bin in that folder? There is only a .htaccess file? Has anyone seen this or can offer any help? Anything would be greatly appreciated. Thanks so much!

htaccess RewriteCond help for new development site

I have having a real problem here and I am hoping someone can help me out - let me explain:
I have a site - domain.co.uk - for the past 6 months this site has been sat on holding pages so google gets to know the domain.
I also have domain.com and domain.org - these were also set up at the same time.
We have a new website under development using a Drupal multisite install where all of the multisites are sub-domains.
Here is my problem!! The new website is now under development and I need to add various rules to the htaccess to redirect back to the holding pages but these rules are new to me and I dont really have a clue what I am doing!
This is what I need to do:
The primary domain is domain.co.uk.
I need to redirect all users requesting domain.co.uk to domain.co.uk/holding/index.php,
but I need to put an IP address exclusion in for us and the developers for testing the new site so we can see what is going on with the new website.
The website also has .com alias and this needs to go to domain.co.uk for all requests.
So here is what I have so far and it does not work as it should:
// I set this to re-write anything except the subdomains I want to see
RewriteCond %{HTTP_HOST} !^(www.domain\.co\.uk)|(subdomain1.domain\.co\.uk)|(subdomain2.domain\.co\.uk)|(subdomain3.domain\.co\.uk)$ [NC]
RewriteRule (.*)$ http://www\.domain\.co\.uk%{REQUEST_URI} [R=302,L]
// then I have put in some rules for checking the ip's and producing a redirect that does not match earlier requests.
RewriteCond %{REMOTE_HOST} !^(xx\.xxx\.xxx\.xx)|(xx\.xx\.xx\.xx)$
RewriteCond %{REQUEST_URI} !/holding/index\.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]
RewriteRule ^(.*)$ /holding/index\.php [R=302,L]
The result so far is:
if a general user goes to the domain.co.uk it redirects to the holding page - GOOD
if a user from the 'excluded ip's address list goes to domain.co.uk they also get redirected - BAD - but if they go to .domain.co.uk/index.php the Drupal site loads with the new design.
If a user from the excluded ip's list goes to subdomain1.domain.co.uk they get redirected to the holding pages - BAD- this, I think, should not happen due to the 1st rule but I am totally lost.
Anyone got any ideas how to get this working so that a user with an allowed ip can access the new website and all it's subdomains but any general user is directed to the holding pages.
Many thanks - my head is about to explode!!
${REMOTE_ADDR} is the IP Address, ${REMOTE_HOST} is the hostname if available.
You could also temporarily add ${REMOTE_ADDR} into the redirect to the holding page to check that you are putting the right addresses in, e.g.:
RewriteRule ^(.*)$ /holding/index\.php?ip=${REMOTE_ADDR} [R=302,L]

Domain Redirects SEO relative to the root folder

I got two related problems in the site root.
First, both "domain.com" and "www.domain.com" works the same way. Is that a problem for SEO purposes? Some guy told to use a redirect. Should I do that? What redirect should I use?
Second, my visitors that visit the site over the "/" url get geolocated and redirect to a specfic page, it means, if the visitor access "www.domain.com" from the city a, he gets a redirect to "www.domain.com/a/", if the visitor came from city b, he gets a redirect to "www.domain.com/b/", etc... How should I work over that?
PS: Feel free to rename the question, I dont know how to name it properly.
Thx
First point answer:
Yes, you should redirect it. Otherwise you can run into the duplicated content issue. You can redirect using .htaccess and the code will be this:
RewriteEngine on
RewriteCond %{http_host} ^site\.com [nc]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,nc,L]
Second point answer:
You can use .htaccess also in this case. But for this question, please bear this discussion in mind (especially my answer).

Apache Rewrite/Redirect different for TLD vs directory

I've migrated the content of a site from one domain to another. I have .htaccess Rewrite set up successfully to redirect any request to the old domain to the same location on the new domain, which is working fine, using the following code:
RewriteEngine On
rewritecond %{http_host} ^roundeltable.com
rewriteRule ^(.*) http://wheelspin.tv/$1 [R=301,L]
However, I want to go a little further. When somebody simply requests the old TLD (http://roundeltable.com/) I want them to be redirected to a specific page within the new domain (http://wheelspin.tv/rt). If they make a request to any other location from the old domain (for example, http://roundeltable.com/about) I want them to be sent to that exact same place at the new domain (http://wheelspin.tv/about) the way they currently are now.
Is this possible? If so, how?
So I've found the solution to this issue, which ended up being provided by somebody from Media Temple's service department. Here's the entire code required in the .htaccess file to make this work:
RewriteEngine On
RewriteRule ^$ http://wheelspin.tv/rt/ [L]
RewriteRule ^(.*)$ http://wheelspin.tv/$1
Obviously substitute whatever domain you want to redirect to in place of mine, but that's the solution for my example. Thanks for the help!
If you want to see all the details on my solution, I have it here: christiaanconover.com/media-temple-service-rocks/