Massilia
Massilia

Reputation: 3

Apache RewriteRule to simulate directory

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 !

Upvotes: 0

Views: 369

Answers (2)

Gumbo
Gumbo

Reputation: 655169

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.

Upvotes: 1

Marcis
Marcis

Reputation: 4617

Yes, it's possible.

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

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

Upvotes: 0

Related Questions