Redirect few pages to new pages on new domain and the rest to the mainpage with .htaccess - .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.

Related

301 redirects / htaccess

Could someone help me please with 301s. I'm moving a website to a new domain but it has a slightly different directory structure.
I've generated an .htaccess file with basic 301s, for example:
Redirect 301 /mypage1.html https://www.mywebsite.com/mypage/1/
Redirect 301 /mypage2.html https://www.mywebsite.com/mypage/2/
Redirect 301 /mypage3.html https://www.mywebsite.com/mypage/3/
This works perfectly. However, I cannot redirect the main homepage, as it seems to break all of my individual 301s.
So if I add:
Redirect 301 / https://www.mywebsite.com
All of my single 301 redirects stop working.
Is there any way I can keep the working 301s and also redirect the homepage too?

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 redirects in .htaccess forming incorrect redirect

I'm trying to redirect http://brisbaneamazingrace.com.au/details.html to http://www.teambonding.com.au/activities/amazing-race-brisbane which is a different domain. In my .htaccess file I have
Redirect 301 http://brisbaneamazingrace.com.au/details.html http://www.teambonding.com.au/activities/amazing-race-brisbane
But the redirect goes to http://teambonding.com.au/activities/amazing-race-brisbanedetails.html
It keeps adding the details.html to the end of the redirect url. Whats up with that?
You should use RedirectMatch for regex matching:
RedirectMatxh 301 ^/details\.html$ http://www.teambonding.com.au/activities/amazing-race-brisbane
Also test this after clearing your browser cache.

301 / plus others , but not all urls

We want to redirect most , but not all, of a website wit a 301 redirect.
Will this work or is the first line to much ?
redirect 301 / http://designers-floor.nl/
redirect 301 /index.php http://designers-floor.nl/
redirect 301 /index.php/woonbeton http://designers-floor.nl/inspiratie/
The Redirect directive will redirect any url starting with the first fragment to the second fragment. The first directive will thus redirect the entire site. (docs)
I recommend testing with temporary redirects until you have accomplished what you want, because testing with permanent redirects will cause those redirects to be cached. Once everything works as expected you can make the redirects permanent. Make sure that the most specific url is always listed first, so that it is matched first.
If you cannot accomplish your goal with just the Redirect directives, you can either use RedirectMatch (docs) or the RewriteEngine of mod_rewrite (docs).

Redirect URL to a Subdomain by .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/

Resources