04-13-2010, 07:04 AM
[eluser]Narkboy[/eluser]
I'm having a night mare with 3 rewrite requirements for a site. Each works on it's own, but I cannot make them work together!
The site is a little odd:
DNS points several domains to the same CI installation - each for it's own country. foo.it, foo.es, foo.co.uk, foo.ca, foo.nl etc. etc. CI grabs the relevant language / localisation and then displays pages. This adds a level of complexity to the rewrite because they must deal with several different domains.
There are 3 rewrite requirements (ordered correctly, I believe, but then it's not working so maybe not):
1) If no subdomain exosts, redirect to www.foo.<ext>. This is mainly for search engines. Everything on the main site should be served from www.foo.<ext>
2) Apart from www, there are any number of possible subdomains that need to be handled by requesting data from index.php/site/<sub-domain>
3) The usual removal of index.php needs to happen.
Examples:
Req 1)
http://foo.es -> should REDIRECT to http://www.foo.es
http://foo.it -> should REDIRECT to http://www.foo.it
Req 2)
http://bar.foo.ie -> should appear the same but load from http://www.foo.ie/site/bar
http://bar.foo.ie/this/topic -> should appear the same but should load from http://www.foo.ie/site/bar/this/topic
Req 3) Pretty obvious.
Req 1 - Rewrite:
This works (on it's own): if HTTP_HOST starts with 'foo', there is no subdomain, so redirect to www.foo. I've not tackled what happens if you enter "foo.foo.co.uk" for example.
Req 2- Rewrite:
This works (on it's own): if the HTTP_HOST is not "www.foo<anything>" AND if the HOST has a subdomain, then request from index.php/site/<subdomain>. I've not tackled appending the rest of the URI as yet.
Req 3 - Rewrite:
This also works (on all my CI apps) to resolve anything except the words listed as index.php/blah.
Running each one on it's own is fine. Adding them together puts me into a loop. The loop is part of req 2 - effectively, entering http://bar.foo.ie (and hoping for http://www.foo.ie/site/bar to be displayed) gives me an infinate loop whereby "site/bar" is requested over and over.
I'm going round in circles and getting really dizzy with this. Please please please - a fresh pair of eyes and maybe some insight?
Thoughts anyone?
Thanks in advance!
Ben
I'm having a night mare with 3 rewrite requirements for a site. Each works on it's own, but I cannot make them work together!
The site is a little odd:
DNS points several domains to the same CI installation - each for it's own country. foo.it, foo.es, foo.co.uk, foo.ca, foo.nl etc. etc. CI grabs the relevant language / localisation and then displays pages. This adds a level of complexity to the rewrite because they must deal with several different domains.
There are 3 rewrite requirements (ordered correctly, I believe, but then it's not working so maybe not):
1) If no subdomain exosts, redirect to www.foo.<ext>. This is mainly for search engines. Everything on the main site should be served from www.foo.<ext>
2) Apart from www, there are any number of possible subdomains that need to be handled by requesting data from index.php/site/<sub-domain>
3) The usual removal of index.php needs to happen.
Examples:
Req 1)
http://foo.es -> should REDIRECT to http://www.foo.es
http://foo.it -> should REDIRECT to http://www.foo.it
Req 2)
http://bar.foo.ie -> should appear the same but load from http://www.foo.ie/site/bar
http://bar.foo.ie/this/topic -> should appear the same but should load from http://www.foo.ie/site/bar/this/topic
Req 3) Pretty obvious.
Req 1 - Rewrite:
Code:
RewriteCond %{HTTP_HOST} ^foo\.([a-z\.]{2,5})$ [NC]
RewriteRule ^(.*)$ http://www.foo.%1/$1 [R,NS]
This works (on it's own): if HTTP_HOST starts with 'foo', there is no subdomain, so redirect to www.foo. I've not tackled what happens if you enter "foo.foo.co.uk" for example.
Req 2- Rewrite:
Code:
RewriteCond %{HTTP_HOST} !^(www\.foo.*)$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z\-\_]*)\.foo\.([a-z\.]{2,5})$ [NC]
RewriteRule ^(.*)$ index.php/site/%1
This works (on it's own): if the HTTP_HOST is not "www.foo<anything>" AND if the HOST has a subdomain, then request from index.php/site/<subdomain>. I've not tackled appending the rest of the URI as yet.
Req 3 - Rewrite:
Code:
RewriteCond $1 !^(index\.php|img|style|license\.txt|robots\.txt|script) [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
This also works (on all my CI apps) to resolve anything except the words listed as index.php/blah.
Running each one on it's own is fine. Adding them together puts me into a loop. The loop is part of req 2 - effectively, entering http://bar.foo.ie (and hoping for http://www.foo.ie/site/bar to be displayed) gives me an infinate loop whereby "site/bar" is requested over and over.
I'm going round in circles and getting really dizzy with this. Please please please - a fresh pair of eyes and maybe some insight?
Thoughts anyone?
Thanks in advance!
Ben