Forum Moderators: phranque
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?
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
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]
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
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?