CodeIgniter Forums
help with mod rewrite and CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: help with mod rewrite and CI (/thread-1924.html)



help with mod rewrite and CI - El Forum - 07-05-2007

[eluser]Waiel[/eluser]
Hi.
i finished my first site based on CI FW and i really love how easy it made my life to finish such project.

The only problem im facing is with the virtual sub domains for the members in the site.

in order to have this i use mod_Rewrite to enable that.
my domain name is something like my-site.com and i made my Mod_rewrite to be like this

Code:
RewriteEngine on
##hide Index.php
RewriteCond $1 !^(index\.php|public|tmp|images|css|javascript|upload|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

##Subdomains redirect
RewriteCond %{HTTP_HOST} ^((.+)\.)?((my-site)\.(com))$ [NC]
RewriteCond $1 !^(index\.php|public|tmp|images|css|www|javascript|upload|robots\.txt)
RewriteRule ^(.*)$ http://%{HTTP_HOST}/index.php/groups/%1 [QSA,L]


basicly each subdomain represents a group and it should point it to http://www.my-site.com/index.php/groups/groupname ..

so if the groupname is Markgroup it should point to http://www.my-site.com/index.php/groups/markgroup


the rewrite code i wrote doesn't work
it will only point to the main page and nothing else ..

Anyone can tell me what i'm doing wrong ..?


Thanks


help with mod rewrite and CI - El Forum - 07-05-2007

[eluser]Waiel[/eluser]
Found the sloution and it worked fine ..

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|public|tmp|images|css|javascript|upload|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1


RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?my-site\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.my-site\.com$ [NC]
RewriteRule ^(.*)$ /index.php/groups/%2 [QSA,L]

hope it will help someone someday Smile


help with mod rewrite and CI - El Forum - 08-31-2007

[eluser]mypcbox[/eluser]
Please forgive my ignorance with rewrite rules but when you say:

Quote:The only problem im facing is with the virtual sub domains for the members in the site.

will this take care of the issue like user1.my-site.com, user2.my-site.com, etc.

I am also in a position where I need to handle virtual sub domains I just wanted to be sure this would work.

Thanks in advance.


help with mod rewrite and CI - El Forum - 08-31-2007

[eluser]Waiel[/eluser]
yes that what i mean
basicly this will help you

Code:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?my-site\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.my-site\.com$ [NC]
RewriteRule ^(.*)$ /index.php/groups/%2 [QSA,L]
in that
if you set anything beside www it will redirect to /index.php/group/Nameofsubdomain

for example

mydomain.mysite.com will be redirected to http://www.mysite.com/index.php/group/mydomain