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

[eluser]rsmithinfo[/eluser]
Hi All,

I have an issue that is sending me a bit nuts.

I have tried a lot of .htaccess files and a lot of altering them to try and make them work and have never got anywhere near this. I have also tried the things posted elsehwere on this forum. This is what I would love to achieve:

domain.com => /welcome/index
www.domain.com => /welcome/index

anysub.domain.com => /subdomain/index/anysub

Can anyone point me in the right direction?

Many thanks
#2

[eluser]rsmithinfo[/eluser]
Just to help anyone who had the same issue as me here is a subdomain .htaccess file that:

- Gets domain without the www and redirects to www
- Rewrites any www.subdomain. or subdomain.www. to subdomain.
- Gets any subdomain (not www) and redirects to a specified controller with the subdomain as variable 1

Hope it's useful!

Code:
DirectoryIndex index.php

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond $1 !^index.php
RewriteRule (.*) /index.php/yourcontroller/index/%1/$1 [L]

RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ ./index.php/$1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB