This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Webmaster forum > March 2007 > Issue with .htaccess





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Issue with .htaccess
Alex

2007-03-09, 6:17 pm

Hey everyone,

I'm having a quite frustrating issue with .htaccess. In order to
redirect all URLs like .com/something/ to .com/index.php/something/
I'm using the following code:

RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

However, now I'm experiencing some issues with my CSS. In it, I'm
linking to some images like this: "/gfx/image.png", but the files
can't be found! Neither if I try to access the images at .com/gfx/
image.png, all I get is a "the file cannot be found".

Now the thing is that it works perfectly with the styles if I remove
the .htaccess file and work with .com/index.php/something/, that's why
I suspect that the .htaccess file is the bad guy.

Anyone has any suggestions?

Rik

2007-03-09, 6:17 pm

Alex <alex.waldner@XXXXXXXXXX> wrote:

> Hey everyone,
>
> I'm having a quite frustrating issue with .htaccess. In order to
> redirect all URLs like .com/something/ to .com/index.php/something/
> I'm using the following code:
>
> RewriteEngine on
> RewriteRule ^$ /index.php [L]
> RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
> RewriteRule ^(.*)$ /index.php/$1 [L]
>
> However, now I'm experiencing some issues with my CSS. In it, I'm
> linking to some images like this: "/gfx/image.png", but the files
> can't be found! Neither if I try to access the images at .com/gfx/
> image.png, all I get is a "the file cannot be found".
>
> Now the thing is that it works perfectly with the styles if I remove
> the .htaccess file and work with .com/index.php/something/, that's why
> I suspect that the .htaccess file is the bad guy.


Enabling you rewrite log would have told you something like this:

/gfx/image.png matches .* from the second rewriterule
/gfx/image.png does not match
^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteCond has ! in front of it, so is satiesfied
URL is rewritten to /index.php/gfx/image.png

So unless you index.php is able to serve the images, the rules are indeed
wrong.
You either alter it to something like this:

RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico|gfx)

Or, something I always like to do:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Saves time in keeping track of every little exception to the rule. It
simply does a redirect if the url requested does not map directly to a
file. This would mean that if you have a dir called 'css', you don't want
to have some page requested like example.com/css/, but as long as you keep
that in mind, everything works quite fluently.
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews