Domain rewriting, loop issue

Using a single web hosting account to host multiple sites

Domain rewriting, loop issue

Postby mindcrash » Sat Apr 04, 2009 1:32 pm

Hi, all. I've been googling this issue for a few hours already. I'm sure someone alreadry found a solution for this problem.

I have a few domains that point to one webspace.

www.domain.com
www.domain1.com
www.domain2.com

domain.com points to webspace root. domains 1,2 are in /vhosts/dom1 and /vhosts/dom2 respectively.

I managed to do proper domain rewriting, like so:

.htaccess in hosting root folder
Code: Select all
Options +Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/vhosts/domain2/
RewriteRule ^(.*)$ /vhosts/domain2/$1 [L]


Each domain points to a proper folder. I'm happy with myself here.

The problem arises when I try to install some CMS demo. Let me showcase with 19-pages CMS. Code above allows to use subdirs without giving me pain.

www.domain2.com/demos/19-pages/

However, 19-pages has own .htaccess

Code: Select all
RewriteEngine on

RewriteRule ^([-a-zA-Z0-9_]*)/?([-a-zA-Z0-9_]*)?$ /index.php?whatpage=$1&maybe=$2


This creates a loop and points to www.domain2.com/index.php
OK, I delete slash in front of index.php and it shows correct 19-pages index, but no images/css because they used absolute path to root, like so
/images/a.png
/style.css
I can edit files fixing paths everywhere but I belive that there is a solution through mod_rewrite. I imagine that I need to use RewriteBase or something alike.

Thank you.
mindcrash
 
Posts: 3
Joined: Sat Apr 04, 2009 1:07 pm

Postby richardk » Sun Apr 05, 2009 2:10 pm

Try
Code: Select all
Options +FollowSymLinks +Indexes

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ /vhosts/example/$1 [L]

and
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteRule ^([-a-z0-9_]+)(?:/([-a-z0-9_]+))?/?$ ./index.php?whatpage=$1&maybe=$2 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mindcrash » Sun Apr 05, 2009 3:53 pm

thanks.
that eliminates loop for index.php (so as removing slash). the only problem left is proper paths to images and css.

*a quick note
images and css have an absolute path in html files
and right now they point to virtual folder root
http://example.com/templates/default/img/logo.jpg
should be through
http://example.com/demos/19-pages/templates/default/img/logo.jpg
and real path from root
/vhosts/example/demos/19-pages/templates/default/img/logo.jpg
mindcrash
 
Posts: 3
Joined: Sat Apr 04, 2009 1:07 pm

Postby richardk » Mon Apr 06, 2009 2:18 pm

images and css have an absolute path in html files

Doesn't the CMS have a base path you can change?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mindcrash » Mon Apr 06, 2009 2:54 pm

Nope.. I actually went to the template and deleted first slash in links, css and images path - and it worked. You see, I don't want to go through the whole source code fixing that.

I still belive that it can be fixed with mod_rewrite. If you had any ideas that would be great.

Thank you.
mindcrash
 
Posts: 3
Joined: Sat Apr 04, 2009 1:07 pm

Postby richardk » Tue Apr 07, 2009 6:48 am

It doesn't sound like a good CMS then.

Mod_rewrite does not change links in the source of pages. The only way would be to redirect all requests to example.com/templates/* to example.com/demos/19-pages/templates/*
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^templates(/(.*))?$ /demos/19-pages/templates/$2 [R=301,L]

(in example.com/.htaccess).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 1 guest

cron