| Author |
|
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 11 May 2011 at 10:41am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 12 May 2011 at 5:10am | IP Logged
|
|
|
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 |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 12 May 2011 at 5:40am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 12 May 2011 at 12:43pm | IP Logged
|
|
|
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 |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 13 May 2011 at 4:18am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 13 May 2011 at 7:40am | IP Logged
|
|
|
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 |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 13 May 2011 at 8:08am | IP Logged
|
|
|
Can I email it?
|
| Back to Top |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 13 May 2011 at 8:11am | IP Logged
|
|
|
Sure, please send it to support@helicontech.com
Thank you.
__________________ Slavik Shynkarenko,
Helicon Tech.
|
| Back to Top |
|
| |