0

I have two domain names pointing to the same server, example.com and myapp.com. I want all requests to http://example.com/params (with zero or more params) to be equivalent to requesting http://myapp.com/controller/method/params. I don't care whether or not the URL includes "www".

Here is my progress so far. Requests for http://example.com/param are not being rewritten as requests for http://example.com/controller/method/param. To clarify, a request for http://example.com/login takes me to the login page accessible from http://myapp.com/login, not the page accessible from http://myapp.com/controller/method/login. It seems there is something wrong with my first rewrite condition, but I can't figure out what.

RewriteEngine on

RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule ^(.*)$ controller/method/$1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?/$1 [L]

I'm using CodeIgniter which is why I am routing all requests through index.php.

I have been playing around with the code above but have not had any luck. Am I on the right track? Thanks in advance.

birderic
  • 3,665
  • 1
  • 19
  • 36
  • Do your assets have absolute links, or relative links? – Joseph Silber Sep 07 '11 at 01:57
  • They are all relative links. If it makes any difference, the functionality I am trying to map the URL to is going to perform a redirect so it's not a problem that the assets aren't loaded. – birderic Sep 07 '11 at 03:03
  • You'll have to set your assets URLs as absolute links. – Joseph Silber Sep 07 '11 at 03:15
  • Sorry, let me rephrase my original question. The problem I am having isn't that the assets aren't loading but that example.com is not routing to the correct page. – birderic Sep 07 '11 at 03:18
  • the rule `RewriteRule ^(.*)$ controller/method/$1 [L]` should be the last – tttony Sep 07 '11 at 05:48

1 Answers1

0

Are you missing the forward slash before controller?

RewriteRule ^(.*)$ /controller/method/$1
minaz
  • 5,385
  • 1
  • 30
  • 28