Forum Moderators: phranque

Message Too Old, No Replies

20.000+ "301 redirects" in .htaccess?

apache mod_rewrite question

         

meetzah2

7:59 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Hello,

I am in final stage of releasing a new version of my website. I have more than 20.000 pages that I must modify the url for.

It is possible for me to make 301 redirects for each of those links? here is an example: as now, my urls are like this: www.example.com/article456.html and after I finish the project, the urls will have this form: www.example.com/title-of-the-article-456.html

do I have to create a 301 redirect in .htaccess for each page?

thank you for your time.

mihai.

TheMadScientist

8:07 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you will have a really tough time getting the title of the article from the old URL to the new one in the .htaccess file, because you really have to have the information as part of the URL now to store/back-reference it so you can put the new URI together...

I suggest finding a php or other scripting language solution, so you can make a database connection and easily manipulate and insert the title to direct visitors to the new page.

You can use Mod_Rewrite to serve the information from the dynamic page you create for the redirects to all of the old URLs requested and assuming you have a pattern to match similar to your example this should be able to be accomplished using 1 to 'a limited number' of rules, which will depend on the pattern(s) present in the exact URLs you need to match and redirect.

g1smd

9:34 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your PHP script MUST check that the requested "title-of-the-article" is absolutely correct for article "456" and if it is not an exact match it must return either a 404 error, or a 301 redirect to the correct URL - otherwise I can link to "/shoddy-stolen-dangerous-goods-456.html" on your site and search engines will happily index and rank your content against that new and perfectly valid URL. It is a perfectly valid URL if your site says "200 OK" when it is requested.

meetzah2

12:12 pm on Oct 11, 2009 (gmt 0)

10+ Year Member



Thank you guys for your replies.
Rather than how to make those redirects, I was interested if .htaccess will handle OK all those lines? it will affect my website performance badly?

jdMorgan

3:35 pm on Oct 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on how many requests you will get, your server's CPU, memory, and disk size/performance, and -if you are on shared hosting- the number of requests to all other Web sites hosted on the same server. In short, it is impossible to predict the 'performance impact' with very much accuracy, except to say that performance will be 'worse' -- a little worse or much worse.

Another factor is the extent to which it may be possible to prevent the redirect code from executing when it is not needed for a particular request; If the old URLs all share some common factor, it may be possible to 'skip' all or most of them when 'new' URLs are requested, thus mitigating the performance impact. So, if all of your old URLs are "/article-<number>.html", then you could make a rule at the very top to detect "/article-<nothing-here><number>", and skip the remaining rules if it matches. Having done that, you server performance over time would be determined by how fast you can get the majority of your inbound links updated to point only to the new URLs.

Jim

Salami1_1

1:23 pm on Oct 20, 2009 (gmt 0)

10+ Year Member



otherwise have a look at RequestMap I'm not an expert on it at all but just came across it during my search. It might help your case (however I think jdMorgan's his suggestion would still be a lot better for performance)

b.r.

jdMorgan

3:52 pm on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe that "RewriteMap" was the intended suggestion, and a good one.

Jim

Salami1_1

12:48 am on Oct 21, 2009 (gmt 0)

10+ Year Member



eeh yes that is indeed what I meant :)