0

How would you mod_rewrite a url to go from

directory.php?id=4 to directory/category/city/name/4/

I took a stab in the dark with

RewriteRule ^directory/*/*/*/([^/\.]+)/?$ directory.php?&id=$4

But not working obviously. Any help is greatly appreciated

Corfro
  • 3
  • 1

1 Answers1

0

How about:

RewriteRule ^directory\.php/.*/.*/.*/(.*)/$ directory.php?id=$1

The parentheses do the capture, and since you are only doing one capture, then the can use '$1' in the target.

Edit: I'm assuming that you want the URL without the query string to redirect to the one with the query string (not 100% clear in your question, sounds like it is the other way around)

jonstjohn
  • 59,650
  • 8
  • 43
  • 55
  • You'll want to remove the `\.php` in the regex to allow URLs of the form `/directory/category/...` instead of `/directory.php/category/...`. – Phil Ross Dec 31 '09 at 19:14
  • i want directory/foo/bar/foobar/4 to re-write to directory.php?id=4 .. still can't get it to work with your suggestions. – Corfro Dec 31 '09 at 20:54
  • JAYKAY - it works with ^directory/.*/.*/.*/(.*)/$ directory.php?id=$1 Thank you very much! – Corfro Dec 31 '09 at 20:56