Welcome to WebmasterWorld Guest from 54.162.168.187

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

In-line images in virtual directories using mod_rewrite

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

New User

10+ Year Member

joined:May 20, 2003
posts:3
votes: 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?

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

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 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

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

New User

10+ Year Member

joined:May 20, 2003
posts:3
votes: 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.

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

New User

10+ Year Member

joined:May 20, 2003
posts:3
votes: 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.

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

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 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

7:23 pm on July 3, 2003 (gmt 0)

Inactive Member
Account Expired

 
 


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?

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members