This forum has been moved here:
Helicon Tech Community Forum

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
Helicon Ape
 Helicon Tech : Helicon Ape
Subject Topic: Dynamic 301 redirects Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
siteone
Groupie
Groupie


Joined: 07 March 2007
Location: United Kingdom
Online Status: Offline
Posts: 51
Posted: 11 May 2011 at 10:41am | IP Logged Quote siteone

Hi,

We use a mapfile to generate dynamic URLs for our e-commerce website.

There are times when we need to change the product URL but want to place 301 redirects for the old URL to keep the search engines happy.

At present we manually add a redirect into .htaccess but we want to automate the process. Is there a way to either generate a mapfile or a SQL db table with old/new URLS that are purely for 301 redirects?

The main problem I am having is working out how to compare a URL to it's 'old' version in the mapfile list so it can then redirect to the 'new' version.

Any help would be greatly appreciated.

Regs,
SiteOne
Back to Top View siteone's Profile Search for other posts by siteone Visit siteone's Homepage
 
Vyacheslav
Admin Group
Admin Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 1542
Posted: 12 May 2011 at 5:10am | IP Logged Quote Vyacheslav

Hello.
Please consider to use mod_dbd: http://www.helicontech.com/ape/doc/mod_dbd.htm

You may use mod_rewrite + mod_dbd, or just mod_rewrite to get new versions from map-file.
The key would be old version, the value—new version.

__________________
Slavik Shynkarenko,
Helicon Tech.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 
siteone
Groupie
Groupie


Joined: 07 March 2007
Location: United Kingdom
Online Status: Offline
Posts: 51
Posted: 12 May 2011 at 5:40am | IP Logged Quote siteone

Hi Vyacheslav,

Thanks for that. I take a look.

The bit I can't get my head round is how to write the regex to pick out the old url and apply the new. I tried the following which didnt work at all:

##Redirect
RewriteCond ${mapfile4:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^/(*)$ /{mapfile4:$1} [NC,R=301]

the mapfile just had
oldurl.html newurl.html

Any ideas?

Cheers
SiteOne
Back to Top View siteone's Profile Search for other posts by siteone Visit siteone's Homepage
 
Vyacheslav
Admin Group
Admin Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 1542
Posted: 12 May 2011 at 12:43pm | IP Logged Quote Vyacheslav

Hello.
Almost correct, please try this one:
Code:
RewriteEngine on
RewriteBase /

# Change mapfile4.txt to the real file name
RewriteMap mapfile4 txt:mapfile4.txt [NC]

RewriteCond ${mapfile4:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.+)$ /{mapfile4:$1} [NC,R=301,L]


__________________
Slavik Shynkarenko,
Helicon Tech.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 
siteone
Groupie
Groupie


Joined: 07 March 2007
Location: United Kingdom
Online Status: Offline
Posts: 51
Posted: 13 May 2011 at 4:18am | IP Logged Quote siteone

Hi Slavik,

Thanks for that but I can't seem to get it to work.

I have two pages urlold.html and urlnew.html

In the mapfile I just have:

urlold.html urlnew.html

I have then pasted your code in to my .htaccess file. It just ignores the rewrite and renders urlold.html in the browser.

If I amend the code to

RewriteCond ${mapfile4:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^/(.+)$ /{mapfile4:$1} [NC,R=301,L]

I get a 'bad request' error and the URL changes to this:

http://www.domain.com/{mapfile4:urlold.html}

I know I'm missing a step somewhere!

Regs,
SiteOne





Edited by siteone - 13 May 2011 at 5:39am
Back to Top View siteone's Profile Search for other posts by siteone Visit siteone's Homepage
 
Vyacheslav
Admin Group
Admin Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 1542
Posted: 13 May 2011 at 7:40am | IP Logged Quote Vyacheslav

Would you please show me all the rules you have. I feel like there is another code which might interfere.

__________________
Slavik Shynkarenko,
Helicon Tech.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 
siteone
Groupie
Groupie


Joined: 07 March 2007
Location: United Kingdom
Online Status: Offline
Posts: 51
Posted: 13 May 2011 at 8:08am | IP Logged Quote siteone

Can I email it?
Back to Top View siteone's Profile Search for other posts by siteone Visit siteone's Homepage
 
Vyacheslav
Admin Group
Admin Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 1542
Posted: 13 May 2011 at 8:11am | IP Logged Quote Vyacheslav

Sure, please send it to support@helicontech.com
Thank you.

__________________
Slavik Shynkarenko,
Helicon Tech.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You can vote in polls in this forum