Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Two Rewrite rules for different site areas?

6:45 pm on Jun 25, 2013 (gmt 0)

Hi Folks, I thought I had my redirect for a new website under development worked out. Lucy assisted with a url rewrite rule - but I have now realised that this doesnt trap all my incoming traffic or redirect properly two different areas of our website.

We have upgraded a Joomla site from 1.5 to 2.5. The site has typical articles and also a Link Directory. To rebuild, we built the new site in a new separate folder. We imported all articles, images etc into the new build so article names stay the same(mostly. BUT - the link directory entries were imported into a new link manager that has now has a very different url structure.

So our basic article URLs are like this :
old format: MJ/hospitality/hospitality-news/hotel-industry/1679-an-article-title
new format: MA/hospitality/hospitality-news/hotel-industry/1679-an-article-title
(the proposed rule is : RewriteRule ^MJ/(.*) http://www.example.com/MA/$1 [R=301,L])

However that doesnt work for my Link Directory URLs:
My link directory urls go from :
Old : /MJ/wsn/hotel-/a-great-hotel-759.html
New : /MA/micedirectory/10277-a-great-hotel
(there is no file type)

From what I understand, the original rule will not work for the link directory urls cos they are a different structure. While the actual listing text part DOES NOT change, the different ID-number and in a different part of the URL (I cant change the ID location from what I understand - its part of the SobiPro database system).

So - is it possible to have two rewrite rules that trap both these two situations ?
My main aim is to still direct already well indexed traffic without a "page not found" error as much as possible.
Thanks so much for any and all hep - its getting urgent as I need to swap sites asap.
7:16 pm on Jun 25, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

The URLs which map "simply" from old to new can be done with a simple RewriteRule. You'll need to use a RegEx pattern that excludes requests that this rule should not process.

Those requests that are for URLs with a non-simple conversion from old to new URL should be internally rewritten to a PHP script that looks up the new URL and issues the 301 redriect from a PHP HEADER directive. The lookup of the new URL could be from a PHP array or from a database table. Use a PHP array if there are less than perhaps a couple of hundred URLs and the list needs to be rarely updated. Use a database if the list is huge and needs to be regularly managed.
7:46 pm on Jun 25, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Old : /MJ/wsn/hotel-/a-great-hotel-759.html
New : /MA/micedirectory/10277-a-great-hotel

Do the old URLs really have a hyphen at the end of a directory name? Consistently? This is something we may be able to work with.

Use a PHP array if there are less than perhaps a couple of hundred URLs ...

Thanks for this. I've occasionally wondered where to draw the large:small dividing line. At least hyphothetically, since I have no intention of messing about with databases so I'll stick with arrays.

... and the list needs to be rarely updated. Use a database if the list is huge and needs to be regularly managed.

What do "rarely" and "regularly" mean in this context? If it were a question of htaccess vs. config file it would depend on how often you restart your server. But isn't a php file fundamentally easier to edit than a database?
9:15 pm on Jun 25, 2013 (gmt 0)

Hi again Lucy. Thanks for jumping in again.
Actually no not all finish with the "-", but about 75% of the top level categories do have the /MJ/wsn/hotel-/a-great-hotel-759.html format.
I can live with that if we can get a solution.

There are 22 total top categories, 6 have an ID number as the top category folder instead of a category name (eg /MJ/wsn/13/a-great-hotel-759.html), 5 top categories have No "-" , There a about 5 , the rest do have the "-"
Oh yes - I will be happy to upgrade & ditch the inconsistancies.

Hi g1smd - thanks for the hints, unfortunately my PHP is verrry limited. I can create a list of urls from the link directory - but its about 4000 links/urls.

This is to be a "permanent" solution - the old site will eventually be killed off. I would be happy to donate to either of you for a working solution.

Thanks to you both.
9:44 pm on Jun 25, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

As always: Start by working out in English what you need to do.

Considering this pair:
which might mean (given that MJ and MA are literal text)


The two questions are:

How do you get from

and from

Or is it the other way around? wsn/hotel- maps to 10277, while 759 maps to micedirectory? Obviously there is no direct relationship between old and new, so it has to be spelled out explicitly-- either by a series of separate RewriteRules, or by a detour to php

In the original
which parts occur more than once?


unfortunately my PHP is verrry limited

One r and I'd think it was a typo. Three and you're conveying a message :)

One nice thing about php is that it's got a very shallow learning curve. You don't need to learn a bunch of behind-the-scenes stuff just to get started. At the most simplistic level, you could take an existing hard-coded html document, change its extension to php, and it would continue to display just fine. Well, except that now you need a server or other php engine; you can no longer open it locally in your browser. But if you're using a CMS, you're beyond that point already.
10:40 pm on Jun 25, 2013 (gmt 0)

Hi Lucy - Yes that was a message :)
Yes I can code html and a few other bits (an old basic & database programmer) and yes I can cope with most cms's. I can follow php but just not confident about coding it (lazy & aging).

The parts occur more than once in bold:

and of course down in the subcategories eg

It is possible I guess to map the old urls and the new ones to an excel file with a bit of work. The only constant at the moment between the old & new is the actual name :
eg :website/MJ/wsn/hotel-/commune-by-the-great-wall-kempinski-beijing-3235.html

The ID's are obviously different for each link/url ie each listing.
The ID numbers differ between old and new and the dividers become underscores. Im not sure but maybe Sobipro can be persuaded to change underscore to dash.
Thanks heaps.

Featured Threads

Hot Threads This Week

Hot Threads This Month