2

So I have mydomain.tld, www.mydomain.tld and res.mydomain.tld all pointing to the same directory: /var/www/mydomain. In that directory, there's my codeigniter application.

So what I'm trying to do is to forward all requests made through res.mydomain.tld to a specific controller called resources.

What I have:

RewriteCond %{HTTP_HOST} ^res\.mydomain\.tld$ RewriteRule ^(.*)$ /index.php?/resources/$1 [L] 

This produces a server error, my rewrite log doesn't provide any clues about why; it just shows some very weird logic being applied to the request string.

Any idea of why this isn't working?

3
  • What kind of server error, a 500 internal server error with the apache error page? Commented Jul 23, 2011 at 19:43
  • 2
    What does the error log say, if you're not getting useful info from the rewrite log? Commented Jul 23, 2011 at 19:43
  • hakre: yes. Michael: just that the request exceeded the limit of 10 internal redirects. Commented Jul 23, 2011 at 19:50

3 Answers 3

4

Leave your .htaccess was before.

In your routes.php

if($_SERVER["SERVER_NAME"]=="res.mydomain.tld"){ $route['default_controller'] = "resources"; }else{ //$route['default_controller'] = Your default controller... } 
Sign up to request clarification or add additional context in comments.

Comments

3

You created a infinite loop. It keeps on rewriting, because the rules always match, and match again. Just add a rule like the following above your rule

RewriteRule ^index.php - [L] 

This will prevent any remaining rules underneath it from executing if the (already rewritten) url starts with index.php

Comments

2

Make sure that index.php isn't matching and going into a rewrite loop:

RewriteCond %{REQUEST_URI} !^index\.php RewriteCond %{HTTP_HOST} ^res\.mydomain\.tld$ RewriteRule ^(.*)$ /index.php?/resources/$1 [L] 

3 Comments

but shouldn't the [L] flag avoid further rewriting of the same request?
@Tom, no because it's not another rule being processed. After the redirect to index.php, the same rule matches again and the redirect happens again. (and again and again)
the [L] prevent rules underneath the current one from being applied. But after it is done and the url has been rewritten, it starts the whole process again for the new url.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.