I saw this code once a long time ago but can't find it now. I need to change the url with using pathaliasing from "/node/1234" to "page/1234" and "article/1234". I know it is a hack but I need it anyway.

TIA

Comments

tesla.nicoli’s picture

correction -- "without using pathalias"

tesla.nicoli’s picture

We have already imported all material to Drupal. But we do not want to create 15,000+ aliases to maintain the paths created from the previous two CMS . Which used the names "page" and "article".

Using path aliasing would not work anyway since we would probably need two aliases for each node in some instances.

Arto’s picture

See Mass URL aliasing in the Handbook.

--
Arto Bendiken -- author of drush, Trace, Boost and Timeline.

carlmcdade’s picture

Untested but this should work. Put it in settings.php

// Example for Drupal 4.7.x and up
function custom_url_rewrite($type, $path, $original) {
  // This path was already aliased, skip rewriting it
  if ($path != $original) {
    return $path;
  }
	
	 if (arg(0) =="node" ) {
		$patterns[0] = '!^node/(\d+)$!';
		$replacements[0] = 'page/\1';
    return preg_replace($patterns, $replacements, $path);
  }
	
  if ($type == 'source') { // URL coming from a client
		$patterns[0] = '!^page/(\d+)$!';
		$patterns[1] = '!^article/(\d+)$!';
		
		$replacements[0] = 'node/\1';
		$replacements[1] = 'node/\1';
    return preg_replace($patterns, $replacements, $path);
  }
  elseif ($type == 'alias') { // URL going out to a client
    return preg_replace('!^node/(\d+)$!', 'display/\1', $path);
  }
}

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders
Try the Drupal 5.0 Demo

kubersluiper’s picture

I was following this thread and would like to clear up the following,

I have a static HTML website with about 1000 articles on there. I thought the only way to get all the articles on a drupal run site was to copy and paste. But after reading this I now wonder if it could be done more automatically.

Would this setting be of any help to me?

sepeck’s picture

Tools
http://drupal.org/project/import_html

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

dakku’s picture

I wanted to try something similar (see http://drupal.org/node/103061), but in my case I wanted:

domain.com/foobar1/mynode-1
domain.com/foobar2/mynode-1
domain.com/foobar3/mynode-1
domain.com/foobar4/mynode-1

would the code above work from a module with a menu_hook?

giorgosk’s picture

GiorgosK
------
Good read for newbies > http://drupal.org/node/120612
Lots of Discussion and help is going on in http://groups.drupal.org/ too, join in

------
GiorgosK
Web Development

carlmcdade’s picture

There have been some changes to 5.0 that are not readily visible. Many have tried to change using this but have recieved a lock out or page not found.

Hiveminds Magazine
http://www.hiveminds.co.uk
for web publishers and community builders CMS Demo Matrix
Coming soon!Drupal Support | Drupal S

tesla.nicoli’s picture

Hiveminds, It works! Thanks!

To the others. I am not sure if this would help for external files. In out case we have incoming links to the old material. The problem was those links would be bad because "page/xxx" would lead to a page not found.

To go to a sub-directory. I have no idea if that would work. The best bet is to do like me and set it up locally and try the code.