Welcome Guest, Not a member yet? Register   Sign In
Subdomain configuration
#1

(This post was last modified: 02-26-2018, 08:37 AM by Parker1090.)

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!
Reply
#2

I may have been approaching this wrong, I'm not sure. However, I did find a solution which uses hooks instead of the htaccess approach.

I wanted to share in case anyone else was looking for the same sort of set up:
https://gist.github.com/chill117/5971561

This does work on CI3 and resolves my issue quite nicely. Hopefully this can help some others in the future - this link seemed to be tricky to find but useful Smile
Reply
#3

Hello,
How to set up a subdomain
Step 1: Log into your account. The first step is to log into the cPanel dashboard for the website you want to add the subdomain to.
Step 2: Add the subdomain. Now, scroll down to the Domains heading and press the Subdomain button.
Step 3: Add DNS records.
Step 4: Wait for your subdomain to resolve.
Regards,
Mika Hawkins
Mika Hawkinsss
Reply




Theme © iAndrew 2016 - Forum software by © MyBB