homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite rule to hide actual path to images.

5+ Year Member

Msg#: 3469784 posted 9:33 am on Oct 5, 2007 (gmt 0)

As part of my CMS users can upload various files to a particular directory on the server.

I would like to write a rewrite to
1) shorten the path to the files
2) stop users being able to see the actual path to the upload directory

I've tried with this
RewriteRule ^CMSimg/*$ /cms/tinymce/uploaded/$1 [NC]

and tested embedding an image:
<img src="/CMSimg/picture.jpg">
But this doesn't seem to work

I wasn't sure if this would work when specifying a src so I ammended the Rule to test
RewriteRule ^CMSimg/$ /cms/tinymce/uploaded/picture.jpg [NC]
<img src="/CMSimg/">

And this worked

Any suggestions on my error in the first example?



WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 3469784 posted 12:56 pm on Oct 5, 2007 (gmt 0)

The "$1" in the right side of this rule refers to --"back-references"-- the part of the requested URL which matches the first parenthesized sub-pattern in the pattern on the left. In essence, it will "copy" that part of the originally requested URL into the new URL-path.

Unfortunately, you have no parentheses in your pattern, so therefore, $1 is undefined.

Also, you must use regular-expressions to construct patterns. Your "^CMSimg/*$" pattern will match a requested URL-path starting with "CMSimg" followed by zero or more consecutive slashes -- The "*" is a regular-expressions quantifier, not a wild-card as it is in DOS, for example. I'd suggest:

RewriteRule ^CMSimg/(.+)$ /cms/tinymce/uploaded/$1 [L]

Based on these problems, I'd like to (kindly) suggest a thorough review of the documents cited in our Forum Charter [webmasterworld.com] -- Using mod_rewrite without a solid understanding is an invitation to disaster: Remember that each directive changes your server configuration, so this isn't to be taken lightly; One single character missing or out of place can cause your server to stop serving files, or perhaps even silently destroy the search ranking of your site over a couple of weeks...


[edited by: jdMorgan at 12:56 pm (utc) on Oct. 5, 2007]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved