.htaccess redirect to oldsite subdomain - .htaccess

I used to have domain say example.com now I hosted new site on this domain, but I could not properly took all the site contents to new site. So, I created subdomain oldsite.example.com and pointed it to my server ip for previous example.com.
Everything is fine here I see my oldsite when I type oldsite.example.com. But rest of the url still refers to example.com/xxx.
All I want to redirect using .htaccess any request coming for example.com/xxx on my previous hosting server to point to oldsite.example.com/xxx.
Note : It's wordpress site.

Putting this into the htaccess in the root folder for the example.com site on your old host, should achieve what you are wanting
RewriteEngine on
RewriteRule ^(.*)$ http://oldsite.example.com/$1 [R=301,L]

Related

htaccess redirect everything on domain to a single page

I'm attempting to replace an entire website with a single landing page on a different domain. So all of the following domains:
example.com
www.example.com
example.com/page-1
example.com/sub/page-2.html
should redirect to:
new-domain.com/landing-page
Currently, I'm using the following .htaccess file (no other content in the file):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(.*)$ http://new-domain.com/landing-page/ [R=301,L]
Additional details:
I'm set up on a GoDaddy Deluxe linux hosting package.
example.com is the "primary" domain of the package, not an addon domain. So by default it directs to the root of the my server space (this .htaccess file is in the root).
I do have several other addon domains, so redirecting all traffic to the server is not an option.
new-domain.com is hosted on the same server space as an addon domain.
The problem I'm running into is that example.com is redirecting to new-domain.com - not new-domain.com/landing-page. All other example URLs listed above redirect as intended.
Any ideas why the non-www domain base wont redirect to the subpage?
It seems it was a caching issue. Tried it in FireFox and the redirect works correctly in all cases. Went back to Chrome, cleared cache and it worked as well.
Apparently, .htaccess 301 redirects may be cashed.

AWS hosted website not working with non-www. But working fine with www

My domain is with godaddy and files are hosted on aws.
website properly working with www.mydomain.abc, but giving error with mydomain.abc
How can I redirect www.mydomain.abc to mydomain.abc
using these redirect rules in .htaccess
RewriteCond %{HTTP_HOST} !^www\.mydomain\.abc
RewriteRule (.*) http://www.mydomain.abc/$1 [R=301,L]
Make sure you have an alias to www from the root domain in your zone:
# IN A 172.17.2.0
www IN CNAME #
To confirm this, ping both 'www.example.com' and 'example.com' and confirm they return the same address.
Update: I corrected the answer per Michael SQL Bot comment below

.htaccess and A record subdomains

I have a wordpress hosting account. I also have a standard web hosting account with the same host. My main website, domain.com is hosted on the Wordpress platform, BUT now I want to add a subdomain for sub.domain.com.
I can't host the script on sub.domain.com as part of the wordpress hosting, so I have been told to create it on my standard web hosting account and then use an A record in the DNS for domain.com to point to the IP of sub.domain.com.
Now, all this works if I visit http://sub.domain.com. However, www.sub.domain.com doesn't work.
What I want to know is, can I edit the .htaccess for domain.com to redirect anyone who visits www.sub.domain.com to http://sub.domain.com?
You can use this:
RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com [NC]
RewriteRule ^(.*) http://sub.domain.com/$1 [L,R=301]
You can't use .htaccess to redirect traffic from www.sub.domain.com to sub.domain.com, because that traffic won't ever get to your server unless your DNS is set up correctly. In other words, if there's no DNS record for www.sub.domain.com, traffic looking for that address will never hit your server, so what is in your .htaccess would be irrelevant.
Keep in mind that you don't have to have www.sub.domain.com - almost nobody will visit that unless you share links using that domain yourself.
That said, if you really want to do this:
Create a sub-sub domain by creating an A record for www.sub.domain.com
Edit the .htaccess file for that sub-sub domain only, adding this rule:
RewriteRule ^(.*) http://sub.domain.com/$1 [L,R=301]

Redirect a subdomain url that has a CNAME

I am looking to 301 redirect a single url on a subdomain to a url on the root domain. Eg:
'sub.domain.com/page' to redirect to 'domain.com/work/name'
I do not want to affect any other pages on the subdomain, the subdomain should operate as normal, aside from that one specific url.
The subdomain also has a CNAME record with the value 'shopname.bigcartel.com'
I tried the .htaccess suggested in my previous question here, but that was before I knew there was also a CNAME record active.
How can I achieve the redirection?
Thanks in advance. Darrell
Add such strings to .htaccess in root of sub.domain.com, not in root of domain.com
RewriteEngine On
RewriteRule ^page$ http://domain.com/work/name [L,R=301]
Must work

Htaccess 301 redirect index.html also redirecting addon domain issue

I have this issue that I can't figure out how to fix:
I am trying to redirect an html site to a wordpress site.
The domain I am trying to redirect as a primary domain which has an HTML site on it obviously with an index.html as the main page.
Now - there are 2 more sites on the same host which use addon domains and sitting in 2 directories:
example.com and example2.com (they are both wordpress sites)
I created an htaccess file, pretty simple and put many lines of redirecting html pages of the primary domain to another domain like so:
Redirect 301 /somepage.html http://www.newdomain.com
Redirect 301 /anotherpage.html http://www.newdomain.com
etc, etc..
at this point all the .html pages were redirecting fine.
Now - the issue is:
I also wanted to point the main page (index.html) to another domain (ww.newdomain.com) so I put this line too (same as I did for other html pages):
Redirect 301 /index.html http://www.newdomain.com
it seemed fine to me but what happened was that it redirects the index.html to the new domain but also redirected the 2 wordpress sites which are sitting in a different directory that I mentioned earlier...
I dont knw why did it happen but I can assum that redirecting the first page that the browser meet redirecting everything on the main root including addon domains.
does anyone have a solution to that?
Thanks
Try changing (which I think you have a typo, I'm guessing it's not the same as the 2nd redirect in the first part):
Redirect 301 / http://www.newdomain.com
to:
RedirectMatch 301 ^/$ http://www.newdomain.com
EDIT: Since there appears to be more than one domain with the same document root try:
RewriteEngine On
# for redirecting "/"
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain.com
RewirteRule ^$ http://www.newdomain.com/ [R=301,L]
# for redirecting "/somepage.html"
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain2.com
RewriteRule ^somapage.html$ http://www.newdomain2.com/ [R=301,L]
etc.

Resources