Forum Moderators: phranque

Message Too Old, No Replies

rewrite rules help

from nnn.html to unkown-text-nnn.html

         

newbies

6:20 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



Dear all,

I have renamed some of my files from original number only file name such as 234.html to something meaningful by using the page title as part of the file name such as "tittle_234.html". For all the files, the number in the file name is the unique identifier and the title is different. How can I redirect the old name to the new one?

Thank you for your help.

jdMorgan

6:27 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are two basic choices:
1) Redirect each old URL to the new URL on a case-by-case basis
2) Use a script to look up the new URL in a database, given the old one

Which of these you choose depends on how many URLs you need to redirect, your level of scripting/database/server config skills, and what privileges you have to configure the server.

Jim

newbies

6:40 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



Thank you Jim!

So there is no simple solution by using some kind of wildcard match in the URL such as
rewrite old/(.*).html new/(.*)$1.html

btw, I have about 30 pages for this.

jdMorgan

6:55 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, you can use wildcards, but all that allows you to do is to 'copy' all or part of the wildcarded value from the old URL into all or part of the new URL. There is nothing to tell mod_rewrite how to "associate" any new value with an old value. mod_rewrite alone has no way to 'find' the new URL unless its value can be derived directly from the 'text' of the old one.

If you have server config-level privileges, you can use mod_rewrite's RewriteMap directive to access a lookup table -- or to call a script that can access your existing database (with new/old URL info added to it), to do the rewriting. But for only 30 URLs, it'd be much simpler to just add 30 Redirect or RewriteRule directives.

Jim

newbies

7:50 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



I guess I will try the hard coded method to add an entry for each file.

Thanks Jim!