Forum Moderators: phranque

Message Too Old, No Replies

image en css redirect trouble

         

randycillekens

9:51 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



Hi,

I got the similar problem as some other on this website. Except the solutions don't work for me.

I will try to explain my my problem:

I have got one hosting package. On this hosting package are running 40 websites. Each in another directory but they are all using the same database.

I have got this piece of htaccess code:

RewriteEngine On
RewriteCond %{HTTP_HOST} website.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ website/index.php [L]
RewriteRule /?([^.]+\.(gif¦jpg¦png¦css¦swf))$ website/images/$1 [L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ website/admin/index.php [L]

What I want is that when somebody type in www.website.nl everything get redirected to index.php in the website directory. But I want all the images (.jpg¦.gif) and .css to get redirected to website/images/<imagename>.<extension>.

But for some reason in the above script he still tries to look for the images in the /images dir in the root (and not in the website directory).
Could somebody please help me. I appoligise for my bad english.

With kind regards,

Randy Cillekens

jdMorgan

12:17 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where is this .htaccess file located?
Do you intend this .htaccess file to affect all 40 hosted sites, or just one?

Jim

randycillekens

4:05 am on Jul 16, 2008 (gmt 0)

10+ Year Member



Hi JD,

My server look like this

..
websitedir1
websitedir2
websitedir3
.htaccess

So the .htaccess file is situated in de root of my webserver.

I intendend to use this one .thaccess file for all of the websites.

Each website has exactly the same code but has other images and other css. The website er build by the index.php in combination with things that are set in the database. (like what is the main content, which menu is to use etc.)

Gr.

Randy

jdMorgan

4:40 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code looks almost correct. I suspect that the problem is that you've used a "control panel" function to map your 40 domains directly to their individual subdirectories. If this is the case, then the root .htaccess file will not be executed for these domains.

The only problem I see is that if this code *is* executed in an .htaccess context, you will get recursion on the image rewrites, resulting in a 500-Server Error, unless you explicitly prevent it:


RewriteEngine on
#
RewriteCond %{HTTP_HOST} websi[b]te\.nl[/b] [NC]
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ website/index.php [L]
#
[b]RewriteCond $1 !^website/images/[/b]
RewriteRule ^(([^/]+/)*[^.]+\.(gif¦jpg¦png¦css¦swf))$ website/images/$1 [L]
#
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ website/admin/index.php [L]

Note: Replace all broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

randycillekens

6:25 am on Jul 16, 2008 (gmt 0)

10+ Year Member



Hi Jim,

This works perfectly! Thanks, I am super happy (now I can finally get some sleep).

Many thanks,

Randy Cillekens

randycillekens

1:00 pm on Jul 19, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Could you please help me out one more time.

I thought I got the hang of it but I still have one problem I can't master.

I have writen an content management system to control every website in my hosting package.

I put the cms in the root in the /beheer directory.

What I want is to redirect everything back to the index of the cms when the url is like www.website.nl/beheer or www.website.nl/beheer/login (or whatever)

This is how my htaccess looks like now. (I have to make it more efficient but this works for now, (except of the cms part).

RewriteEngine On
#
RewriteCond %{HTTP_HOST} nederland-vacatureland\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/fckeditor
RewriteCond %{REQUEST_URI} !^/beheer
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/beheer
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ nederland-vacatureland/index.php [L]
#
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/fckeditor
RewriteCond %{REQUEST_URI} !^/beheer
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/beheer
RewriteCond $1 !^nederland-vacatureland/images/
RewriteRule ^(([^/]+/)*[^.]+\.(gif¦jpg¦png¦swf))$ nederland-vacatureland/$1 [L]
#
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/fckeditor
RewriteCond %{REQUEST_URI} !^/beheer
RewriteCond %{REQUEST_URI} !^nederland-vacatureland\.nl/beheer
RewriteCond $1 !^nederland-vacatureland/css/
RewriteRule ^(([^/]+/)*[^.]+\.(css))$ nederland-vacatureland/$1 [L]
#
RewriteCond %{REQUEST_URI} ^/beheer
RewriteCond %{REQUEST_URI} ^nederland-vacatureland\.nl/beheer
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ /beheer/index.php [L]

This is what I thought happend here:
- When the requested url is like /beheer everything except the *.js,ico,gif,jpg,png,css,doc files are redirected to /beheer/index.php

beheer is a directory in the root (where the htaccess file is).

Thanks in advance.

Randy Cillekens

jdMorgan

4:02 pm on Jul 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your fourth rule will never be invoked, because the two RewriteConds can never both be true at the same time -- The requested URL-path cannot start with *both* "/beheer" *and* "nederland-vacatureland.nl/beheer". Note that the second RewriteCond also blocks invocation, because REQUEST_URI will always start with a slash -- unlike the URL-path 'seen' by RewriteRule in .htaccess.

Furthermore, if the rule *was* invoked, it would create an 'infinite loop' because it would rewrite /beheer/index.php to /beheer/index.php.

You need to add a RewriteCond to fix this looping problem, and modify the first two RewriteConds to do whatever it is that you intended them to do -- perhaps add an [OR] flag to the first one?.


RewriteCond %{REQUEST_URI} ^/beheer [b][OR][/b]
RewriteCond %{REQUEST_URI} [b]^/n[/b]ederland-vacatureland\.nl/beheer
[b]RewriteCond %{REQUEST_URI} !^/beheer/index\.php$[/b]
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css¦doc)$ /beheer/index.php [L]

Jim