Welcome Guest, Not a member yet? Register   Sign In
Problem with .htaccess - Subdomain
#11

[eluser]gRoberts[/eluser]
Code:
$Parts = explode('.', $_SERVER['HTTP_HOST']);
$Path = 'www';
if(count($Parts) >= 3)
  $Path = $Parts[0];

var_dump($Path);

The above code is not perfect, as I have had to deal with the fact that your users may try going to http://www.domain.com, http://subdomain.domain.com or http://domain.com

You can get around this by using the .htaccess file to force the www if not supplied,

Code:
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

meaning you can simply use

Code:
$Parts = explode('.', $_SERVER['HTTP_HOST']);
$Path = $Parts[0];

Your database would then just need to pass the $Path to the query to return data related to the subdomain.

This will prevent you from having to create routes that pass the subdomain along, where as, each page will simply parse the url of the page and determine the data based on that.




Theme © iAndrew 2016 - Forum software by © MyBB