Setting up 301 redirects for multiple domains merging to single domain - .htaccess

I've got a tricky situation where four different websites are now merging into a single site. I'm trying to figure out the best way to handle 301 redirects for old URLs from these sites.
Here's an example for illustration. Say I have these four sites:
https://red.com
https://blue.com
https://green.com
https://magenta.com
And they're all now going to be living just at https://red.com.
Each of these sites had a "Team" page...
https://red.com/team/
https://blue.com/team/
etc.
Once I've pointed all the URLs to the same place, I'd like to see if someone tried to enter one of the previous URLs, and direct them to a specific new place on the site, e.g.:
URL Entered: https://blue.com/team/
301 Redirect: https://red.com/blue/team/
URL Entered: https://green.com/team/
301 Redirect: https://red.com/green/team/
etc.
Since folks may be coming from multiple different domains, I can't use standard relative 301 redirects in .htaccess for this. I'd like to just be able to point the DNS for these other domains to go straight to red.com, and then handle the 301 redirect logic there.
Any ideas on how to handle this?

You can simply use 302 temporary redirect rather than using 301 which is permanent.
** Also don't forget to clear previous 301 redirection caches on your web browser; if used.

Related

Redirect full http-link to https-domain on another server

I'm not sure if this even is possible to do, but I have two different domains on two different webservers. Both have a SSL-certificate. What I need is for all links on domain1 (both http and https) to be redirected to domain2 with https. Example:
http://domain1.com/customlink should be redirected to https://domain2.com/customlink
Also https://domain1.com/customlink should be redirected to the same as above.
Is this possible to achieve by having a .htaccess file with some rules on the webserver of domain1.com? It is important that whatever the user writes after domain1.com, also will be kept in the new redirected link.
I'm not sure if this even is possible to do .... my host told me that you cannot redirect https://example.com/SOMETHING and keep the part after slash onto the new domain
I feel there must be something more to this question, as otherwise, this is just a standard domain redirect...
two different domains on two different webservers
Both have a SSL-certificate.
Assuming there is only 1 domain (ie. domain1.com) hosted on the first server that you want to redirect.
Then, in your .htaccess file at domain1.com, use a mod_alias Redirect:
Redirect 302 / https://domain2.com/
You should remove all other directives in the .htaccess file at domain1.com in order to avoid potential conflicts (they aren't being used anyway, since you are redirecting everything).
The mod_alias Redirect directive is prefix-matching, and everything after the match is passed on to the target. eg. /foo/bar/baz is redirected to https://domain2.com/foo/bar/baz. Everything (HTTP and HTTPS) is redirected to domain2.com (HTTPS).
This is currently a 302 (temporary) redirect. Only change to a 301 (permanent) - if that is the intention - once you have confirmed this works as intended. This is to avoid any potential caching issues.

htaccess redirect specific pages to another domain

I’m having some real problems with 301 redirects in my .htaccess file.
I have about 20 pages on an old site that I need to redirect to pages on a new site. The URL structure of the new site is totally different.
Here’s one that I tried:
Redirect 301 /dan-carr-gear-list/travel-gear https://dancarrphotography.com/gear/travel/
Unfortunately, this doesn’t work.
What happens is that you get redirected to https://dancarrphotography.com/gear/travel-gear/ for some reason.
I just can’t figure it out.

.htaccess 301 redirect for thousands of entries or RewriteMap

I have a site with thousands of pages that need to be redirected. I was thinking of using a 301 redirect in my .htaccess, but I'm just afraid that this will be very inefficient.
Would having a .htaccess with thousands of lines (there is no way to have a re-write rule, they have to be mapped one by one), mean that every time someone accesses one of our pages, they have to read the entire .htaccess? Is that a bad thing? This sit is in a shared host.
I saw a previous answer here about using RewriteMap. How is that different than having the 301 redirects?
Thanks
For simple page redirects 301 is the best and it's very fast. RewriteMap is for more complex rewrite functions or doing very specific rewrite tasks.
Before black listing your pages server side, I would try remapping with your application first.
If you set up the redirect with .htaccess those pages will be dead to Google which of course may or may not be a bad thing. Basically once Google indexes those redirects there really is no going back (SEO).
In short redirect wisely.

301 Redirect from Dynamic to .html. Wants to 404 orginal

I apologize if in the wrong place. I have someone that has done 301 redirects where dynamic pages are being redirected to show .html. (www.printe-z.com/computer-checks to www.printe-z.com/computer-checks.html) They feels they should now use a custom 404 page for the original page(s); www.printe-z.com/computer-checks. What do you think? Leave it the way it is?
301 is better for this scenario, specially for search engines: they will associate your old urls with the new ones so you'll keep your pages rank.
People accessing your old links will be benefited too since they will be automatically redirected to new urls.
If the page has moved use 301. If it is removed all together, 404.
301 tells crawlers such as googlebot that the original page is moved permanently to the target page. So keep it as it is.
For your information, most URL rewritings are done using 301 Permanent Redirects. Also sending domain.com visitors to www.domain.com is an example where 301 redirection is used.
People might have bookmarked the old urls, or there may be a link on a website to the old url. Unless you are sure this is no longer the case, which you never can, you can remove the 301. But this is in a perfect world.
If the 301's are a maintenance burden, or have some other negative side-effect and the 301 have been there for some time ( >1 year), you could just remove them. But if not just leave them be.

Trouble redirecting all pages in a folder to a page at root level

I've searched, tried various examples, and none, other than creating an explicit list of redirect statements seems to work.
The biggest issue I have is that, although I have access to deploy web pages to the site, I do not have access to any web hosting control panel - site access was inherited, and until now it's been fine, but I think that it is either running an old version of apache, or rewrite rules are not allowed.
Anywa, over the years, the site has changed several times, and after registering the site with Google Webtools, I found the list of pages that gave crawl errors, so created an HTACCESS file to deal with these.
Over the years, there have been folders deployed and named in camel case and all lower case, and so all I wanted to do was to redirect all files in a folder to the new folder in the .htaccess file level, i.e.
My .HTACCESS currently has 120 lines, and an example batch are as follows:
redirect 301 /challenge/stanley_steamer.htm /lsr_history.html
redirect 301 /challenge/stanley_steamer.html /lsr_history.html
redirect 301 /Challenge/index.htm /lsr_history.html
redirect 301 /Challenge/Record.htm /lsr_history.html
redirect 301 /Challenge/Stanley_Steamer.htm /lsr_history.html
redirect 301 /Challenge/Sponsors/Avery_Weigh-Tronix.htm /sponsors.html
redirect 301 /contact/index.html /contact.html
redirect 301 /design/details.html /design.html
redirect 301 /design/index.html /design.html
redirect 301 /Design/Engine-drive_train.htm /design.html
redirect 301 /Design/Rear.htm /design.html
redirect 301 /Design/Home_Page.htm /design.html
redirect 301 /Design/index.htm /design.html
As you can see, I have some cases where the folder name is camel, others lower, and other cases where there is a htm and an html file of the same name that is listed in the crawl error log.
All I want to do is, in the example above, redirect all pages from /Challenge/ and /challenge/ to lsr_history.html, but all files in /Challenge/Sponsors/ to sponsors.html.
I also have a huge list of individual team pages that I list one by one and each one redirects to the new team page.
I've tried examples like:
RedirectMatch 301 ^/[Cc]hallenge/ /challenge.html, but this returns a 'Error 404 Not found'.
Any ideas or examples of how I can cut down my htaccess file to simplify this will be gratefully received.
Regards
Martin
I wouldn't bother searching for cases inside the match string for this kind of thing if I could avoid it - have you tried just specifying the RedirectMatch in lowercase, and appending [NC] to the end of every line? (that will tell mod_rewrite to ignore case and match regardless, which may save you some time)
if you have collections of similarly-formatted rewrites, why not group them together with one particular set of rules for each? That way you could cover, for example, all incoming URLs with one subdirectory with one rule, and all incoming URLs with a single subdirectory one with another rule. If nothing else, it could help simplify viewing the .htaccess file :)
(Take everything I suggest with a massive dose of salt, I'm still getting to grips with the black magick of mod_rewrite myself)

Resources