Redirect URL to a Subdomain by .htaccess - .htaccess

I am trying to redirect a URL to a subdomain
I am already redirecting form a old domain to a new domain
Like http://abc.com to http://xyz.com by the below code
RewriteEngine on
Redirect 301 / http://xyz.com/
So my Url becomes http://xyz.com/blog/
Now I want to redirect http://abc.com/blog/ to http://blog.xyz.com
How can I do this

You don't need to turn the rewrite engine on, as the Redirect directive is part of mod_alias. You can add the other redirect before the one that redirects to xyz.com:
Redirect 301 /blog/ http://blog.xyz.com/
Redirect 301 / http://xyz.com/

Related

Redirect few pages to new pages on new domain and the rest to the mainpage with .htaccess

I am trying to setup a redirection with .htaccess file.
So far I have this:
Redirect 301 /temat-konfiguracja-internetu-w-a2mobile https://infomobile.pl/konfiguracja-internetu-w-a2mobile-22500
Redirect 301 /temat-konfiguracja-mms-w-a2mobile https://infomobile.pl/konfiguracja-mms-w-a2mobile-22499
Redirect 301 /temat-jak-sprawdzic-stan-konta-w-a2mobile-oraz-inne-kody-ussd-w-a2mobile https://infomobile.pl/jak-sprawdzic-stan-konta-w-a2mobile-oraz-inne-kody-ussd-w-a2mobile-1812
Redirect 301 /temat-jak-sprawdzic-swoj-numer-telefonu-w-a2mobile https://infomobile.pl/jak-sprawdzic-swoj-numer-telefonu-w-a2mobile-22497
Redirect 301 /temat-konfiguracja-apn-internetu-i-mms-samsung-galaxy-s4 https://infomobile.pl/konfiguracja-apn-internetu-i-mms-samsung-galaxy-s4-11561
Redirect 301 /forum-internet-mobilny-w-a2mobile https://infomobile.pl/internet-mobilny-w-a2mobile-31
Redirect 301 /temat-ostrzegam-roaming-nie-dziala-w-a2mobile https://infomobile.pl/ostrzegam-roaming-nie-dziala-w-a2mobile-22494
Redirect 301 /temat-stan-konta-a2mobile https://infomobile.pl/stan-konta-a2mobile-22498
Redirect 301 /temat-rozwiązany-problem-z-konfiguracja-apn-na-urzadzeniu-meizu-m2-mini https://infomobile.pl/rozwiazany-problem-z-konfiguracja-apn-na-urzadzeniu-meizu-m2-mini-1817
Redirect 301 /temat-logowanie https://infomobile.pl/logowanie-761
Redirect 301 /mapa-index.xml https://infomobile.pl/sitemap/sitemap.xml
But... for all the other pages I want to setup a whole domain redirection (so for all the pages that are not on the list I want to point aero2forum.pl to infomobile.pl). Is there any way to accomplish this?
To redirect everything else to the root of the target domain you will need to add a (mod_alias) RedirectMatch directive after your existing (mod_alias) Redirect directives.
For example:
:
# Redirect everything else to the target domain's homepage
RedirectMatch 301 ^ https://example.target/
However, it should be noted, that from a search engine perspective, multiple redirects to the homepage will likely be seen as a soft-404. (And reported as such in Google Search Console.)
This does assume that the source and target domains point to different server's. Otherwise, this will naturally result in a redirect loop. You could avoid the redirect-loop by not redirecting the homepage, eg. ^/.. However, if both domains point to the same server then you will need to convert everything to use mod_rewrite instead and explicitly check the requested hostname.
Aside: You cannot use a (mod_rewrite) RewriteRule here since it will take priority over the existing Redirect directives (regardless of the order) and end up redirecting everything to the homepage of the target domain.

301 Redirection for any url in my website

I need to create a 301 redirection from myOldSite.com to myNewSite.com
I have this code in the htaccess in myOldSite.com
#Redirect 301 / https://myNewSite.com/myPage/
This works fine to redirect myOldSite.com but it does not work to fire the right redirection for myOldSite.com/services.html:
myOldSite.com is properly redirected to myNewSite.com/myPage
But
myOldSite.com/services is redirected to myNewSite.com/myPage/services.html This is wrong.
As you can see servicesis appended to the end. This is not what I need. I need:
myOldSite.com/services to be redirected to myNewSite.com/myPage
Any url which start with myOldSite.com/ANYTHING_HERE should be redirected to myNewSite.com/myPage
Use RedirectMatch
RedirectMatch 301 / https://myNewSite.com/myPage
This will not append the old URL subpath to the destination URL.

.htaccess 301 redirect to site B with referrer from site A

I am trying to make the following redirection with .htaccess
Redirect 301 pageA.php to https://newSite/pageB.php?referrer=pageA.php
I need the pageA.php to be redirected to another site along with a referrer from the origin site containing pageA.php
Is there a way to do this in htaccess?
Try below code
RewriteRule ^/pageA.php https://newSite/pageB.php?referrer=pageA.php [R=301,L]

301 Redirect in .htaccess is appending old file path/name to new url

I have two URLs: old-site.com and new-site.com.
My root folder on the old-site.com has NO FILES in it but only the .htaccess file. I don’t want to use the old domain anymore. However, I do want to pass the link juice to the new domain. Therefore, I created 301 Redirects in the .htaccess file and put it in the root folder on the old-site.com.
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
My entire .htaccess looks like this (I skipped a few links to shorten it):
#Begin 301 Redirects
Redirect 301 / https://www.new-site.com/
Redirect 301 /contactus https://www.new-site/contact-us/
Redirect 301 /rentals https://www.new-site/lodging/
Redirect 301 /lift.html https://www.new-site/our-rentals/boat/
Redirect 301 /rentals.html https://www.new-site/our-rentals/
Redirect 301 /map.html https://www.new-site/contact-us/
Redirect 301 /giftshop https://www.new-site/store/gift-shop/
#End 301 Redirects
I don’t have any Rewrites. The above is my entire code.
The following redirect works fine:
Redirect 301 / https://www.new-site.com/
However, any other redirect creates the following absolute path on the new-site.com with a 404 error:
If I redirect:
Redirect 301 /contactus https://www.new-site/contact-us/
It goes to:
https://www.new-site.com/old-site.com/contactus
or
If I redirect:
Redirect 301 /lift.html https://www.new-site/lift/
It goes to:
https://www.new-site.com/old-site.com/lift.html
Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?
Thank you,
Derek
Your rules will not do what you need correct because of this line Redirect 301 / https://www.new-site.com/ which will match any request first and if you put it in the last it will also match any request so , if you want it to match only root use RedirectMatch to be able to use regex like this :
RedirectMatch 301 /?$ https://www.new-site.com/
By this the rest of rules will work as expected .
Note: clear browser cache the test

301 redirect isn't working

I have a blog that I'm trying to redirect to a different domain.
Old domain: http://harrisonfjord.com
New domain: http://agoodman.com/blog/
Google states that you should do 301 redirection for all pages, so I took a list of urls from my XML sitemap and just manually set up the redirection.
Here's what I've put in my .htaccess file: http://pastebin.com/PkKNbJKf
The file structure is the same across both domains, so I can simply redirect each page as follows:
redirect 301 http://harrisonfjord.com/ http://agoodman.com.au
redirect 301 http://harrisonfjord.com/whatever http://agoodman.com.au/blog/whatever
However, this currently isn't working. Do I need to put the redirection in an tag or something?
What if you redirect your old-domain to new new domain completely?
# redirect an entire site via 301
redirect 301 / http://agoodman.com/blog/
Also try using RewriteEngine as:
RewriteEngine On
RewriteRule ^(.*)$ http://agoodman.com/blog/$1 [R=301,L]

Resources