2

I am devoloping a website with htaccess rules. This is the url structure:

example.com
example.com/index.php/login
example.com/index.php/foo
demos.example.com

For the last url above (demos.example) I would like to do show the content of example.com/index.php/demos, for this reason, I have create a .htaccess file as follow:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?demos.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/demos [L]

When I browse demos.example.com the index page is displayed (example.com), as nothing had happended. I hope that my explanation has been clear.

  • I have readed this topic, but this solution do a "browser redirection" and that is not the idea.
  • Using this example produces nothing: the index is displayed instead of index.php/demos

Update

If I use the .htaccess as follow:

RewriteCond %{HTTP_HOST} ^(www\.)?demos\.example\.com 
RewriteRule ^(.*)$ index.php/demos/$1 [L]

...this make that the browser display a 500 internal server error. Viewing the log, it prints the following messages:

[Thu Dec 06 15:06:24 2012] [error] [client 201.192.30.254] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3112): [client 201.192.30.254] r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /, referer: http://example.com/ 
Community
  • 1
  • 1
manix
  • 14,537
  • 11
  • 70
  • 107

1 Answers1

1

Try this:

RewriteCond %{HTTP_HOST} ^(www\.)?demos\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/index.php/demos/$1 [L]
Geo
  • 12,666
  • 4
  • 40
  • 55
  • This make a browser redirection instead for "point", as I mencioned in the post – manix Dec 06 '12 at 21:59
  • Ah, so you want it to keep the URL intact, but show contents from another domain? I don't think it's possible actually.. Is it? I mean, I'm sure you should be able to do this via setting up a virtual server in your DNS records. But with .htaccess.. I doubt. – Geo Dec 06 '12 at 22:03
  • I think that it is posible. It is not from another domain, is just another "segment" from same domain. – manix Dec 07 '12 at 00:09
  • Right, a subdomain. Okay, I'll be curious to see a solution myself then. – Geo Dec 07 '12 at 03:36
  • Well, It is not possible show content from another domain, but It is possible from the same domian (using the file name instead of full url). However, to make it works I has been a little hack but in the application side, nothing more to do with the .htaccess – manix Dec 07 '12 at 19:02