views:

45

answers:

1

Hi, I'm trying use mod_rewrite to rewrite URLs from the following:

http://www.site.com/one-two-file.php 

to

http://www.site.com/one/two/file.php

The folders don't exist, but "virtually" exist for the rewriting purpose.

What rule do I used in this?

+1  A: 

Untested:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.php$ $1-$2-$3.php [L]

I can't really understand your explanations about virtuality and existence: one-two-file.php must exist or you'll have nowhere to redirect to.

Update

The previous version works fine when used from an .htaccess file. However, if used from main http.conf file you need to add leading slashes:

RewriteRule ^/([^/]+)/([^/]+)/([^/]+)\.php$ /$1-$2-$3.php [L]

I presume that's why it wasn't working for the OP (he was probably getting a 404 not found status code).

Álvaro G. Vicario
They are called "path segments" - so one/two/file.html goes to one-two-file.php :)
Shamil
Unfortunately, this doesn't work :(
Shamil
Does it not work in any special way? How are you testing exactly? Is mod_rewrite loaded and enabled?
Álvaro G. Vicario
Hi, was adding it directly to httpd.conf.Thanks :)
Shamil