Redirect 301 clarification - .htaccess

I've done a fairly standard 301 redirect from www.olddom.com to www.newdom.com.. and for whatever reason google change of address tool doesn't like it - which has sent me down a rabbit hole on the rewrite rules and noticed almost every blog I read has a slightly different way of writing it.
Please can somebody confirm the rewrite code needed for .htaccess when it must include the following 2 things:
Forward all domain variants (http://olddom.com, https://olddom.com, http://www.olddom.com and https://www.olddom.com) to https://www.newdom.com)
Keep URL location (olddom.com/about gets forwarded to https://www.newdom.com/about).

Related

Partial 301 redirects & SEO strategy

This is somewhat of a subjective question. But would like the communities take on this. My client is doing a site split. www.domain1.com will turn in to -- www.domain1.com + www.domain2.com. I know this isn't typically advisable from an SEO perspective, but they are doing it for legal reasons.
Our plan is to only rip out the product pages on www.domain1.com and add those on www.domain2.com everything else on domain1 will stay and everything else on domain2 will be original content. So here's the question, still a good idea to do single page 301 redirects for the pages that are transferred?
www.domain1.com/apples > www.domain2.com/apples
I know that's a bit open-ended, without a ton of detail, but if you have specific examples of where you've done something similar, I'd be curious to know what worked/didn't.
Yes, with a clarification: http 301 is the best for your purpose, because it means permanent redirect (good for SEO, you pass the page and domain authority, link juice...); instead a 302-redirect (http 302) means a temporary redirect, you have no time limits but all the SEO value won't pass! For your purpose, you don't want that.
In general, all pages should be redirected with http 301. Aniyway, with data analysis you can make a decision: if you have a page unuseful, with no traffic, it doesn't need to be redirected, you can use http 404 or http 410 (you can build also a custom 404 page!).
The last thing, must avoid multiple redirects, for example: instead of site1-->site2-->site3 you just need to do: site1-->site3. The reason is each redirect hurts loading speed (also the most common and useful redirect, from http to thhps!!). You just need to avoid multiple ones.

Setting up 301 redirects for multiple domains merging to single domain

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.

Redirect rule creates loop

I have a redirect rule on htaccess that simply points a parent page to its child page.
Redirect 301 /swu-members-only/ /swu-members-only/home/
However, when I try to access the page i'm trying to redirect, it returns a URL like this: http://simonwu.com.au/swu-members-only/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home
What causes the redirect loop like this to happen? Any suggestions to fix is greatly appreciated.
The reason for the redirection loop is that the pattern you rewrite also matches your target path. So when the client sends the next request to the specified target it again gets redirected...
You can get around that by forcing an exact match:
RedirectMatch "^/swu-members-only/?$" "/swu-members-only/home/"
Another option is to use the rewriting module which offers much more flexibility:
RewriteEngine on
RewriteRule "^/?swu-members-only/?$" "/swu-members-only/home/" [R=302]
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug, they really slow down the http server, often for nothing and they can open pathways to security nightmares. They are only provided for situations where you do not have access to the real http servers host configuration (read: really cheap service providers).

.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.

redirect from old mod-write to new one

So I had a mod re-write all set up for a client who was hosting their site on a shared server with GoDaddy. After nearly of year of working they contacted me and GoDaddy had changed something that made the re-write not work properly. It would work sometimes but not all the time. Anywway, it liked nice URLs such as http://siteurl.com/employee/19/ as opposed to http://siteurl.com/employee-19 from what I was reading it had something to do with it not ending in a slash but either way, the first one works now.
However is there a way to create a redirect from the old modrewrite rule to the new one. I tried this but had never really done rewrites on the htaccess file before so I could have set it up wrong.
redirect /employee-19 http://siteurl.com/employee/19/
But that spits back an error 301, any thoughts on how to fix this or is it just a lost cause at this point?
But that spits back an error 301, any thoughts on how to fix this or is it just a lost cause at this point?
A 301 is what you want. It tells browsers and search engine indexing bots that http://siteurl.com/employee-19 is equivalent to http://siteurl.com/employee/19/ but to use the latter from now on. The content has permanently moved from the first to the second URL.
If you want a more generalized form, you can use RedirectMatch:
RedirectMatch 301 ^/employee-([0-9]+) http://siteurl.com/employee/$1/

Resources