• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anybody help me with subdomain -> uri value mod_rewrite?

Hey folks... Im having some issues getting mod_rewrite working the way I want with a CI project... I think it may be a conflict between my rule and the basic CI rules. Was hoping you fine people might be able to help me out.

The idea is that http://anything.mysite.com (except www.mysite.com) will be rewritten to http://mysite.com/x/anything

So... my current .htaccess file is functional but doesn't do quite what I want it to...

I have it working as a redirect but would prefer it was transparent to users so they would always see http://anything.mysite.com

RewriteEngine On

RewriteBase /

#default controller stufF:
RewriteRule ^(index(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

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

RewriteCond %{HTTP_HOST} !www.mysite.com [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mysite.com [NC]
RewriteRule ^(.*)$ http://mysite.com/x/%2/$1 [L,R=301]


# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

further examples for clarity:

http://bob.mysite.com -> http://mysite.com/x/bob
http://sam.mysite.com/stuff -> http://mysite.com/x/sam/stuff
http://mary.mysite.com/#hash -> http://mysite.com/x/mary#hash

wildcard dns already functions properly... only issue is changing from a redirect causes a 500 and/or an infinite loop.

Any thoughts would be greatly appreciated.

I've googled every variation on this theme I can think of but haven't found help that gets me where I want to be.

.htaccess tips and tricks - There are 2 pages.

Thanks for the link... theres actually some good info in there but it doesnt directly address my question.

I've started to think that it may not be possible to do what I want... either due to a conflict in my other htaccess rules or maybe CI or server config.

Gonna go a different route and have the default controller detect the subdomain and handle it right there.

Just as a followup resolution post...

didn't get my way with htaccess but this will work just fine

function index(){
     $subdomain_arr = explode('.', $_SERVER['HTTP_HOST']);
     if(count($subdomain_arr) == 3){
          $check = $this->amodel->check_valid_subdomain($subdomain);
          //else it has a valid subdomain so do subdomain stuff:

     } else {
          //no subdomain... do regular stuff

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.