httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rose, John B" <jbr...@utk.edu>
Subject [users@httpd] mod_rewrite for multiple unknown directories question
Date Thu, 13 Aug 2015 15:33:02 GMT
Hello

We are trying to create a RewriteRule that will allow us to drop a component of the actual
URL, and still reference the content deeper in the directory structure for any number of subdirectories
to that dropped component of the URL.

For example let's say the content for each account is in ....

/home/user1/assets/images
/home/user1/assets/images/houses
/home/user1/assets/images/cars
/home/user1/assets/someotherdirectory/

/home/user2/assets/images
/home/user2/assets/images/pets
/home/user2/assets/anotherdirectory
/home/user2/assets/anotherdirectory/yetanotherdirectory

Etc.

We want web developers to be able to reference that content WITHOUT the "assets" component
in the URL

As in ...
http://abc.com/user1/images/houses/1.jpg
http://abc.com/user2/anotherdirectory/yetanotherdirectory/test.js
Etc.

We seem to be able to do this if we explicitly name the directories involved ...


The image is in /home/user1/assets/image but we want to reference it with /user1/image.


It worked with this:

...

RewriteEngine on

RewriteRule ^user1/image(/.*|)$ /home/user1/assets/image/$1 [L]...

...


But we need to make that more generic, there may be large number of user areas with various
subdirectories with content. We would like to be able to have one rule, or set of rules that
we can apply to each user area without any edits needed by them.

We tried this ....


We want it to work regardless of what's after the /assets", it won't always be "/images",
it might be /js, /css or whatever...

We tried the following, unsuccessfully:

...

RewriteEngine on

RewriteRule ^user1/([a-z0-9]+)/(.*|)$ /home/user1/assets/$1/$2 [L]
...

We tried to match image/someotherdirectory/anotherdirectory directories using ([a-z0-9]+)
and set it to $1.

This rewrite rule passed an htaccess tester we found online but failed on real apache. I realize
that doesn't necessarily mean anything.



Thanks



Mime
View raw message