0

I'm new to Drupal and created a basic page in which the clean url is

/todo

If I want the todo's for a certain month I can do

/todo?month=januaray

However what I would like to do is provide a clean url which looks like

/todo/januaray

I tried modifying my .htaccess file like explained here

RewriteCond %{REQUEST_URI} ^/todo/(.*)$
RewriteRule ^.*$ /todo?month=%1 [L]

But that didn't seem to work. Is there any easy way to achieve this?

  • Without knowing the exact functionality you're going for, it's really tough to give an answer. Can you expand on your question by providing what modules you're working with and what you're trying to achieve? – Lester Peabody May 1 '12 at 15:44
  • Look into defining a path with a wildcard using hook_menu. – Sam152 Jun 16 '13 at 5:11
  • If you are using a view with exposed filter, look on this page drupal.stackexchange.com/questions/22989/… – GwenM Jul 18 '13 at 10:43
1

This will work:

RewriteRule ^todo/(.*)$ todo?month=$1 [L,QSA]

No need for the rewrite condition.

That will internally forward, e.g. http://example.com/todo/january to http://example.com/todo?month=january.

Make sure you add that code before Drupal's main index.php RewriteRule

  • I tried your suggestion and it still doesn't seem to work. I pasted it before the RewriteCond's above the RewriteRule for index.php. It is telling me The requested page "/todo/january" could not be found. I am using the path module too and the system name for the todo basic page is node/3. Could that effect it at all? – Danny May 1 '12 at 17:03
  • Ah sorry I misunderstood, didn't read the question properly. Since the alias is stored in Drupal, and isn't a real file, you won't be able to do this with .htaccess. I can think of a quick hack you could do in a custom module if that's any good to you? – Clive May 1 '12 at 17:11
  • I'd rather not do a custom module, I'll just live with the dirtier version of the url. – Danny May 1 '12 at 17:14
-3

I would consider using Pathauto as it is way more flexible and easier to use.

The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change.

  • Core path module (which Pathauto uses) doesnt allow parameters in url. – Sinan Erdem Jun 10 '15 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.