Page 1 of 1

.htaccess trick to insert www

Posted: Wed Nov 12, 2008 5:59 pm
by rhamej
I was having trouble with iCMSUser setting a cookie for the PHPBB forum board and for CMSMS.

The problem I was having was that if you came to the site via http://mysite.com and logged in, then came back to http://www.mysite.com, the cookie didn't set.

So, I found this little snippet of code that will re-write the url to always be http://www.mysite.com.

If someone has a better way, I'd like to hear it  :)

Code: Select all

RewriteEngine On

#------------code added to default .htaccess file-----------------
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
# ------------------------------------------------------------------------------

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Re: .htaccess trick to insert www

Posted: Wed Nov 12, 2008 6:13 pm
by JeremyBASS
here is an alternet one I list before on here

# force CMSMS www IN URL
RewriteCond %{HTTP_HOST} !^www\.yourDomain\.com [NC]
RewriteRule ^(.*)$ http://www.yourDomain.com/$1 [R=301,L]
# END CMSMS force www IN URL


there are many ways... what may work for one may not work for all :)

Re: .htaccess trick to insert www

Posted: Thu Nov 13, 2008 3:20 pm
by Pierre M.
Please please please... webserver tuning is not CMSms specific. The webserver's documentation and support board have their own places.
http://httpd.apache.org/docs/2.2/rewrit ... onicalhost

Pierre M.

Re: .htaccess trick to insert www

Posted: Thu Nov 13, 2008 7:47 pm
by JeremyBASS
Pierre M. wrote: Please please please... webserver tuning is not CMSms specific. The webserver's documentation and support board have their own places.
http://httpd.apache.org/docs/2.2/rewrit ... onicalhost

Pierre M.
I agree but it is worth a mention IMHO here as it can make a big difference in the running of CMSMS... This is a prime example where the webserver tuning in more or less CMSms specific... but as I say above too there are many ways... what may work for one may not work for all ...

:)

in the end I hope this helps someone... as I'm sure that was the intent of this post...

have great one today...
jeremyBass

Re: .htaccess trick to insert www

Posted: Thu Nov 13, 2008 7:49 pm
by rhamej
JeremyBASS wrote:
Pierre M. wrote: Please please please... webserver tuning is not CMSms specific. The webserver's documentation and support board have their own places.
http://httpd.apache.org/docs/2.2/rewrit ... onicalhost

Pierre M.
I agree but it is worth a mention IMHO here as it can make a big difference in the running of CMSMS... This is a prime example where the webserver tuning in more or less CMSms specific... but as I say above too there are many ways... what may work for one may not work for all ...

:)

in the end I hope this helps someone... as I'm sure that was the intent of this post...

have great one today...
jeremyBass
What he said. I was just trying to help out. For me it was CMS related as it was fix to a quirk in one of the modules.
Owell...
Cheers,
Josh

Re: .htaccess trick to insert www

Posted: Fri Nov 14, 2008 5:59 am
by JeremyBASS
In the interest of being helpful...

For those that did the trick with multiple domains virtual folder theory which allowed for only one cmsms install  1*  2** (which by the way is prefect for iCMSUser you can look back for that post for when I worked the two together) there is an issue using the two described ways above... you would always be at www.domin1.com when you wanted to go to www.domin1.net... so building off the first work I did that kermit improved on, I push it much farther but have not had a chance to write on it... I fix that issue described by using this:

so with the thought that you main is  domain1.com this is what you do....

Code: Select all

# force www IN URL 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
# END force www IN URL 


so it works with the .htaccess that makes the virtual folder system work...

Code: Select all

#(mind you the below could be domain2.com aswell)
#first cmsms RW
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

# second domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain1\.biz [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /BIZ

# second domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain1\.info [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /INFO

# second domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain1\.net [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /NET

# second domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain1\.org [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /ORG

....etc

When I get more time I'll write out the a-z I have woked out on multiple domains and sites under one CMSMS install in another post... lots more cool trick dealling with blogs, sitemap MS, additions on kermit's menu strategy, .htaccess stuff like this etc...

It may not be bullet proof but I hope this helps... Super sites are a real possblity with CMSMS.

have a great one
jeremyBass

1*http://forum.cmsmadesimple.org/index.php/topic,22564.0.html
2**http://forum.cmsmadesimple.org/index.php/topic,22890.0.html