user143520
user143520

Reputation: 491

How to rewrite part of the url with .htaccess?

I'm not that good with .htaccess, so I wonder, how can I rewrite default 'node' part of the url to an 'article' for example, so that server will output 'article/1' instead of 'node/1'. I need this to be done on a server side, so with the use of .htaccess only. Any guess?

Upvotes: 1

Views: 993

Answers (2)

ceejayoz
ceejayoz

Reputation: 180024

The Pathauto module will allow you to set customised paths like this in Drupal. It's a must-have for Drupal (should be in Core, really). Just install and configure via the easy web-interface and you'll be all set.

You can even have different patterns for different node types. As an example, if you had 'page' and 'news' content types, your pages could have URLs like http://example.com/about-us while your news items could have urls like http://example.com/news/2009/05/28/news-post-title.

Upvotes: 3

chaos
chaos

Reputation: 124297

Well, the first problem is that you don't understand what mod_rewrite (which is what's doing the work you want, not .htaccess) does. It doesn't change the HTML you're outputting; it changes how the server interprets incoming URL requests.

So if your Drupal install understands node/1 and you want people to see article/1, first you need to modify the HTML output so it embeds links to article/1. Then you rewrite from article/1 to node/1 like so, in a .htaccess or Apache config file:

RewriteEngine on
RewriteRule article/ node/ [NS]

Upvotes: 0

Related Questions