Jump to content

Routing subdomain to subfolder


lucashermsen

Recommended Posts

Dear forum members,

 

My hoster redirects all traffic to subdomain.domain.com to domain.com/subdomain. Since I work with CodeIgniter, I would like it to route it to domain.com/applications/subdomain. Therefore, I have written an htaccess in the root folder:

 

 

RewriteEngine on

RewriteRule ^subdomain(.*)$ /applications/subdomain.php/$1 [L]

 

However, this gives an internal server error (500).

 

Does anybody have a clue how I can best do this?

 

Best regards

Lucas

Link to comment
https://forums.phpfreaks.com/topic/272756-routing-subdomain-to-subfolder/
Share on other sites

1. Are you sure they're actually redirecting traffic to that location and not, say, setting the document root of the subdomain to be a subfolder under wherever the domain.com files are kept? (eg, /home/lucashermsen/domain.com/subdomain)

2. Do you have mod_rewrite installed? Just checking.

3. What does Apache's error log say about the 500 error?

I think they are indeed doing this:

 

"setting the document root of the subdomain to be a subfolder under wherever the domain.com files are kept? (eg, /home/lucashermsen/domain.com/subdomain)"

 

What can I do to have subdomains use the /application/subdomain/ folder?

If you don't mind people actually being redirected to domain.com/application/subdomain.php then you can do that: create a .htaccess in the domain.com/subdomain folder with

Redirect permanent / http://www.domain.com/application/subdomain.php

 

Otherwise if the URL has to still show the subdomain then in that same .htaccess try

RewriteEngine on
RewriteRule ^ /full/path/to/domain.com/application/subdomain.php%{REQUEST_URI} [L]
# if that doesn't work then try without the ${REQUEST_URI}

...and if that doesn't work either then I'm not sure. I don't think [PT] will help because the target isn't a URL, can't use Alias in a .htaccess... Might have to find some way to force the PATH_INFO variable.

 

 

[edit] All this assumes that CI won't muck around with the URL, like change the hostname or automatically include "/application/subdomain.php" or something equally fatal.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.