Welcome Guest, Not a member yet? Register   Sign In
Can anybody help me with subdomain -> uri value mod_rewrite?
#1

[eluser]BadZombi[/eluser]
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

Code:
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.


Messages In This Thread
Can anybody help me with subdomain -> uri value mod_rewrite? - by El Forum - 04-19-2012, 03:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB