Welcome Guest, Not a member yet? Register   Sign In
Subdomain to folder in 'controllers'
#1

[eluser]markbeekman[/eluser]
Hi,

I am new and I am looking for a solution to the following problem. In my 'controllers' folder I created a 'm' folder for a mobile application. Also I created a subdomain 'm' via DirectAdmin. If I put a index.html file in a 'm' folder on the server, the subdomain works. But what I want is the following.

When a user visits 'http://m.example.com' I want to show (not redirect) them the file at 'http://example.com/m/'. Also I want to know the other segments like when visiting 'http://m.example.com/controller/function/value' will show 'http://example.com/m/controller/function/value'.

I searched for a few days and tried a lot of .htaccess codes, but I could not find the solution. I am more like a designer who knows a little bit about developing instead of a die hard programmer. I would appreciate it if you guys could help me. Thanks!

Mark

ps: I deleted the 'm' folder on the server because I don't want to use a 'm' folder. I searching for a solution using the .htaccess file in the root of the website (if possible).
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You could try using routing: http://ellislab.com/codeigniter/user-gui...uting.html

You can also tell from within your app whether or not the request is coming from a mobile, and display the appropriate view instead. http://ellislab.com/codeigniter/user-gui...agent.html

However, if the user is using a mobile, why not redirect?
#3

[eluser]markbeekman[/eluser]
I don't think I can fix this using de CodeIgniter functions, because CI is in my root directory and I am doing a request to the subdomain 'm'. There is no 'm' folder with any CI files.

Let's say I have a portfolio website called http://markbeekman.nl where I have a controller called 'projects', a function called 'websites' and a value called 'projectx'. I could visit 'projectx' using the url http://markbeekman.nl/projects/websites/projectx.

For the desktop website I use this structure. For the mobile website I'm using a folder inside the 'controllers' folder called 'm'. I could visit the same project on the mobile website using the same structure like http://markbeekman.nl/m/projects/websites/projectx That works fine!

But I would like another url structure for the mobile website using a subdomain called 'm'. I would like the visitors to visit http://m.markbeekman.nl/projects/websites/projectx and show them the page http://markbeekman.nl/m/projects/websites/projectx without the url to change.

I had one solution, creating a 'm' folder on the server and within that folder a .htaccess. But I would like to have no 'm' folder on the server, only with one .htaccess file. I guess / hope I could fix the same result with the .htaccess folder inside the root folder. Is this possible? Thanks!

Current .htaccess file inside root:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#4

[eluser]markbeekman[/eluser]
I fixed it using the .htaccess code below:

---

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^m\.example\.com$
RewriteRule ^ http://example.com/m%{REQUEST_URI} [L,P]

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

---

Changed example.com to my own url of course. Thanks for helping anyway! Is this .htaccess code above okay? Or should I change [L,P] to something like R=301?
#5

[eluser]TheFuzzy0ne[/eluser]
I think you're making this more complicated than it needs to be.

Just use $this->input->is_mobile() from within your controller, and serve up the mobile view if it's a mobile making the request.

You could also give browser clients and mobile clients different configurations quite easily with CodeIgniter.

Let's say you have the following Web root structure:

Code:
/browser
/mobile

You map your domain name, and the www subdomain to the /browser directory, and map the m subdomain to /mobile.

Inside each of these, you have a separate index.php file (which can load the same app), but use your index.php file to set the ENVIRONMENT.

Now your app will know which site is being accessed, and you can have two different sets of configuration files.

I have done this with my development server, so in ./application/config I have a directory called "development". When my development server responds to a request, it loads the configuration files from ./application/config/development. If the file doesn't exist, it loads the file from ./application/config instead.

I suspect the only file you'll end up needing in ./application/config/mobile would be routes.php

You can find more information about running multiple configurations at the following URLs:
http://ellislab.com/codeigniter/user-gui...ments.html
http://ellislab.com/codeigniter/user-gui...vironments

Hopefully this makes sense. If not, tell me what you're unclear on, and I'll try to help you out.
#6

[eluser]TheFuzzy0ne[/eluser]
I don't really understand redirection types, so I can't really comment.




Theme © iAndrew 2016 - Forum software by © MyBB