views:

39

answers:

2

Hi StackOverflow !

is there a way to tell Apache to simulate a directory in the URL ?

Here is what I'm trying to do... I currently have an URL like http://photo.mydomain.com/pics/17/120417/1.jpg and I would like to be able to reach the same content with an URL like http ://photo.mydomain.com/pics/51/17/120417/1.jpg .

Is that possible ? If yes, a little of bit would be much appreciated :-)

Thanks !

A: 

Yes, it's possible.

RewriteEngine On
RewriteRule ^pics/\d{2}/(.+)$ pics/$1

"\d{2}" would be "51" and "(.+)" means one or more symbols

Anpher
Thanks, but the rule doesn't seems to work and I'm getting a 404. I've enable rewrites logging and I'm seeing that the rules is properly interpreted.
Sylvain V
@Sylvain V: Add the R flag and show us the url your getting
Anpher
ok, rewrite has been changed to RewriteRule ^pics/\d{2}/(.+)$ pics/$1 [R] and the returned URL doesn't changed, if I add the /51/ or not, and I'm getting a 404 with /51/
Sylvain V
A: 

Try this rule:

RewriteRule ^pics/\d{2}/([^/]+/[^/]+/[^/]+)$ pics/$1

Edit     Since you’re using this rule in the <VirtualHost> section and not in a .htaccess file, you need to use the full path with path prefix in the pattern:

RewriteRule ^/pics/\d{2}/([^/]+/[^/]+/[^/]+)$ pics/$1

Only in .htaccess files you need to remove them:

When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done.

Gumbo
Thanks, but the rule doesn't seems to work and I'm getting a 404. I've enable rewrites logging and I'm seeing that the rules is properly interpreted.
Sylvain V
@Sylvain V: Do you use any other rules that might get in conflict with this one?
Gumbo
no, in this vhost, there is only this rule
Sylvain V
@Sylvain V: And where do you use this rule? Did you try other rules to verify that mod_rewrite is enabled and working?
Gumbo
yes, in another vhost I've a website running which is using rewrites and that works properly
Sylvain V
@Sylvain V: Ok, in that case you need to prepend `/` to the pattern. I thought you wanted to use it in the .htaccess file.
Gumbo
This is working like a charm !! Thank you so much !
Sylvain V