You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Rose, John B" <jb...@utk.edu> on 2015/08/13 17:33:02 UTC

[users@httpd] mod_rewrite for multiple unknown directories question

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



Re: [users@httpd] mod_rewrite for multiple unknown directories question

Posted by Rich Bowen <rb...@rcbowen.com>.
Pardon me for answering a question with a question, but is it possible 
to just move the directory that you're pointing to to remove this confusion?

That is, I assume that the URL /user1 is Aliased to /home/user1/ 
somewhere in your configuration. Can you alias it to /home/user1/assets 
instead and eliminate the middle-man?

--Rich

On 08/13/2015 11:33 AM, Rose, John B wrote:
> 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
>
>
>


-- 
Rich Bowen - rbowen@rcbowen.com - @rbowen
http://apachecon.com/ - @apachecon

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org