Configuring mod_rewrite in .htaccess for PN legacy URLs in

cel4145 - June 26, 2003 - 16:43

I'll be migrating Kairosnews from PostNuke to Drupal CVS this weekend. Since the site has almost 2000 stories, I'm concerned about the fact tha any links to them from around the web will go dead. Some consolation is that the .htaccess rules will take those dead links and refer them to the home page instead of 404ing them.

Can .htaccess be configured to rewrite the urls? The node ids will be taken from the current story id's, so that part will not be a problem.

The current PN default story url looks like this:
modules.php?op=modload&name=News&file
=article&sid=1972&mode=nested&order=0&thold=0

so it seems like it could be rewritten to

node/view/1972

Is this possible? Admittedly, I know very little about mod_rewrite. Any suggestions would be helpful.

Try this

Anonymous - June 26, 2003 - 17:02

Something like this should work:

RewriteRule ^modules.php?op=modload&name=News&file
=article&sid=([1-9][0-9]*)* node/view/$1

----------------
Mr PHP :: Professional Website Services

re: Try this

cel4145 - June 27, 2003 - 01:17

Thanks so much! It would have taken me quite a few hours to figure that out. I'll try it out on Saturday :)

This works for me with Drupal 4.6.x

frjo - January 19, 2006 - 06:48

[Updated 2006-01-19]

I could not get the above RewriteRule to work. After som trial and error I come up with the following rules. They will rewrite the syndicate link and really old "...article&sid=123" links also.

# Rewrite PN legacy URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/backend.php
RewriteRule ^backend.php /rss.xml [R=permanent,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^op=modload&name=News&file=article&sid=([1-9][0-9]*)*$
RewriteRule ^modules\.php /node/%1? [R=permanent,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^sid=([1-9][0-9]*)*$
RewriteRule ^article\.php /node/%1? [R=permanent,L]

The "?" after "%1" stops the query string from being attached to the URL.

Start from those in the .htaccess file

Dries - June 26, 2003 - 17:07

It is possible. Take a look at the mod_rewrite rules that are part of the .htaccess file that ships with Drupal; it should be fairly straightforward to alter these.

 
 

Drupal is a registered trademark of Dries Buytaert.