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