homepage Welcome to WebmasterWorld Guest from 54.227.89.236
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
In-line images in virtual directories using mod_rewrite
Spork




msg:1502573
 8:37 pm on May 20, 2003 (gmt 0)

Ok so I know this question has been beaten to death, but I have yet to find anyone else with this problem.

I'm using mod rewrite to rewrite virtual directories in the web root, i.e. www.domain.com/foo rewrites to www.domain.com/index.php?channel=foo

I'm using:
RewriteCond %{REQUEST_URI} ^/([a-z]+)/?$
RewriteRule ^([a-z]+[^/]*)/?$ channel.php?channel=$1 [L]

So far everything works, however upon going to www.domain.com/foo the style sheet wont load, and if I try vising www.domain.com/foo/ with the trailing slash, no images or any other inline objects using relative paths are loaded.

I assume this is because the browser still believes /foo/ is a real directory and therefore is requesting all inline objects as /foo/path/to/image/

I know people do this all the time and get it to work, what am I missing?

 

jdMorgan




msg:1502574
 9:55 pm on May 20, 2003 (gmt 0)

Spork,

You have mapped all requests, regardless of resource type to index.php. If index.php cannot handle image and stylesheet requests, then of course, they won't load.

Use an additonal RewriteCond to exclude requests for anything except "pages" and allow requests for images, ccs, js, etc. to be passed through unmodified. Alternatively, modify index.php to properly serve up images, etc.

HTH,
Jim

Spork




msg:1502575
 10:23 pm on May 20, 2003 (gmt 0)

Ah I understand what you mean, the image requests fit the test pattern so are getting redirected as well.

I'm not really sure how I would allow images to pass through though.

Spork




msg:1502576
 10:57 pm on May 20, 2003 (gmt 0)

the answer to this was so simple i feel like shooting myself.

I simplified my rewrite to:

RewriteEngine on
RewriteRule ^([a-z]+)/?$ channel.php?channel=$1 [L]

then made all my image and resource calls start with a / so they escape the test pattern.

I feel like a certified retard.

jdMorgan




msg:1502577
 11:29 pm on May 20, 2003 (gmt 0)

Spork,

As an example of excluding filetypes from your rewrite:

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(exe¦css¦js¦jpe?g¦gif)$
RewriteRule ^([a-z]+)/?$ /channel.php?channel=$1 [L]

This will prevent requests for .exe, .css, .js, .jpeg, .jpg, and .gif files from being rewritten, regardless of what directory they are in (at or below the directory in which this code resides).

Note that posting on this forum changes the pipe characters to broken pipe "¦" characters. You will need to change them back to solid pipes before use.

HTH,
Jim

eirinikos




msg:1502578
 7:23 pm on Jul 3, 2003 (gmt 0)

jdMorgan:

I'm having the same problem spork reported here. I know I could an absolute image path relative to the URL, as in "/images/etc.." but I'd rather not be dependent upon that because the site is accessible via its domain and as a subfolder under the host company's url. If I make all image paths "/images..." then none of them will work if someone hits the site through the second mentioned method.

I tried using the rewritecond that you posted, but it does not work. I caught the remark that the pipes needed to be changed back to the solid variety, which I did.

Here is what my .htaccess file looks like, it's pretty simple.

RewriteEngine On
RewriteCond %{REQUEST_URI}!\.(exe¦css¦js¦jpe?g¦gif)$
RewriteRule ^headlines/(.*)/(.*)/(.*)$ index.php?pid=2&func=$1&arg0=$2&arg1=$3
RewriteRule ^content/(.*)$ index.php?pid=3&content=user&func=main&arg0=$1

Might you have any other suggestions for solving this problem?

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