Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Subdomain configuration

$
0
0
Hi all

Appreciate this has been covered a few times here and there, but I've tried several solutions and nothing seems to be working for me - so any guidance would be really appreciated!

I'm trying to keep things somewhat easy to maintain for myself with shared config and models etc. I have several parts to my CodeIgniter setup which would be accessed through a subdomain, but internally would just be a controller folder. For example:
  • admin.domain.com --> domain.com/admin
  • users.domain.com --> domain.com/users
  • users.domain.com/my-account --> domain.com/users/my-account
  • accounts.domain.com --> domain.com/accounts
Each of these subdomains are fixed (it's not a wildcard subdomain), but the only way I've figured out how to do this with CodeIgniter is point them all at the same directory and basically route based on htaccess rewrites to the index.php file, seems they're all controller folders (routes also plays a part in this) - although I'm very much open to better suggestions.

I've tried a few solutions from Stackoverflow. One in particular seemed to fit my use case better than the others, but I tried this one but this just gives me object not found errors.

This is my htaccess based on this:
Code:
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /

   # If it's not a file being accessed
   RewriteCond %{REQUEST_FILENAME} !-f
   # If it's not a directory being accessed
   RewriteCond %{REQUEST_FILENAME} !-d
   # And if it's domain.com, with or without www (no subdomain)
   RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
   # Rewrite all requests to index.php adding the query
   # string (QSA) and terminating all subsequent rewrite
   # processings.
   # See: https://httpd.apache.org/docs/current/rewrite/flags.html#flag_end
   RewriteRule ^(.*)$ /index.php/$1 [END,QSA]

   # If it's not starting with www
   RewriteCond %{HTTP_HOST} !^www
   # And is a subdomain
   RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.domain\.com$ [NC]
   # Rewrite the request to index.php/test/SUBDOMAIN/whatever...
   RewriteRule ^(.*)$ /index.php/%1/$1 [END,QSA]
</IfModule>

I'm aware this is for wildcard domains, but even if that works, it would be a step forward for me.

I have run this through a tester (here), and it's returned fine, so I'm a bit lost as to why it's returning "Object not found".

I'm not an expert with htaccess so I've been going around in circles, so any pointers would be great!

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>