Welcome to WebmasterWorld Guest from 54.158.54.179

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite rule to hide actual path to images.

     
9:33 am on Oct 5, 2007 (gmt 0)

5+ Year Member



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?

12:56 pm on Oct 5, 2007 (gmt 0)

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



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...

Jim

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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month