.htaccess 301 redirect for thousands of entries or RewriteMap - .htaccess

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.

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.

Too many Rewrite Rules in .htaccess

I had to redesign a site last week. The problem is that last urls weren't seo friendly so, in order to avoid Google penalizing my site because too many 404 errors, I have to create a lot of Rewrite Rules because all the content had awful URL's ( and that content had a good position on SERP's).
For example:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas http://%{HTTP_HOST}/1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [R=301,L]
Is this a problem on my performance? Is there another solution to my situation?
Thanks
They are in the same domain.
Then an internal redirect is much better. A header redirect sends the new URL to the browser and causes it to make a new request; an internal one is handled, as the name says, internally.
This should work:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas /1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [L]
Any performance issues are going to be negligible with this - except maybe if you have many thousands or tens of thousands of individual rules, those may slow down Apache. In that case, if you have access to the central server configuration, put the rules there instead of a .htaccess file, because instructions in the server config get stored in memory and are faster.
A. Yes using 301 is the right way to notify search bots about changed URLs and eventually your old URL's will be removed from search results.
B. You don't need to use %{HTTP_HOST} in your rewrite rule just use it like this:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas http://%{HTTP_HOST}/1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [R=301,L]
C. If you have lots of RewriteRules like above I recommend using RewriteMap or else use some scripting support (like PHP) to redirect from old to new URL with 301.

301 Redirect vs Rewrite

I have a site that was hosted by someone else all the web pages were .html files. I am now hosting the site and have changed it to a wordpress site. The domain has not changed but obviously all the pages have. What is the best way to redirect all the .html pages to the main url?
301 Redirect in an .htaccess does not require the mod_rewrite library. It's a much simpler way to redirect, but it doesn't have the flexibility and power you get using the Rewrite rules. If you have a 1-1 mapping with explicit urls you can use the Redirect:
Redirect 301 /path/file.html http://new.site.com/newpath.php
If you're trying to do wild card matching of a number of similar patterns using regular expressions you'll need to use Rewrite.
RewriteRule ^(.*).html$ http://new.site.com/$1.php [R=301,NC,L]
Here's a pretty good overview of the 2 methods: http://www.ksl-consulting.co.uk/301-redirect-examples.html
There is also RedirectMatch that also does wild card matching of similar patterns using regular expressions. The choice depends on just what you need to do.
Rewrite is complex - learning curve - but you can serve alternative urls without giving a HTML code and things that seem imposible. But with great power comes complexity and lots of bugs.
If you are only doing a simple redirection - possibly matching some urls - redirect is the way to go.
When you can't do it with Redirect, you will probably want to start learning Mod_Rewrite.

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.

Resources