ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

www help

January 24, 2010 1:09pm

Subscribe [2]
  • #1 / Jan 24, 2010 1:09pm

    Oxygen Solutions

    40 posts

    Hello, i use lg .htaccess and it generates and works great with the site I am working with however I want to add the www. rather than take it away.

    LG .htaccess uses the following code:

    RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    I have tried lots of different things for it to work that anyone visiting the site without the www gets redirected to the www but nothing works, even the code you would use on normal sites.

    Any help is appreciated

  • #2 / Jan 24, 2010 3:07pm

    Focus Lab Dev Team

    1129 posts

    Try replacing it with this

    RewriteCond %{HTTP_HOST} !^www\.$ [NC]
    RewriteRule ^ <a href="http://www.%{http_host}%{request_uri}">http://www.%{http_host}%{request_uri}</a> [L,R=301]
  • #3 / Jan 24, 2010 3:11pm

    Oxygen Solutions

    40 posts

    thanks for replying so quick, that adds an extra www. so site doesnt work at all, but could this maybe be because of the rest of LG .htaccess code?

  • #4 / Jan 24, 2010 3:12pm

    Focus Lab Dev Team

    1129 posts

    thanks for replying so quick, that adds an extra www. so site doesnt work at all, but could this maybe be because of the rest of LG .htaccess code?

    I’m not sure, can you share the full htaccess? I’ve never used that extension from Leevi

  • #5 / Jan 24, 2010 3:14pm

    Oxygen Solutions

    40 posts

    please see below, its used to get rid of the index.php etc

    # secure .htaccess file
    <Files .htaccess>
     order allow,deny
     deny from all
    </Files>
    
    # Dont list files in index pages
    IndexIgnore *
    
    # EE 404 page for missing pages
    ErrorDocument 404 /index.php?/{ee:404}
    
    # Simple 404 for missing files
    <FilesMatch "(\.jpe?g|gif|png|bmp)$">
      ErrorDocument 404 "File Not Found"
    </FilesMatch>
    
    RewriteEngine On
    
    RewriteBase /
    
    # remove the www
    RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Add a trailing slash to paths without an extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule ^(.*)$ $1/ [L,R=301]
    
    # Remove index.php
    # Uses the "include method"
    # <a href="http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method">http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method</a>
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/({ee:template_groups}|{ee:pages}|members|P[0-9]{2,8}) [NC]
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    # Remove IE image toolbar
    <FilesMatch "\.(html|htm|php)$">
      Header set imagetoolbar "no"
    </FilesMatch>
  • #6 / Jan 24, 2010 3:15pm

    Oxygen Solutions

    40 posts

    thanks so much though, im a bit of a newb in this area!

  • #7 / Jan 24, 2010 3:18pm

    Focus Lab Dev Team

    1129 posts

    I’ve tested this on my domain and it works properly. If you replace this:

    # remove the www
    RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    with this:

    # force the www
    RewriteCond %{HTTP_HOST} !^www\.$ [NC]
    RewriteRule ^(.*)$ <a href="http://www.yourdomain.com/$1">http://www.yourdomain.com/$1</a> [R=301,L]

    does it work?

  • #8 / Jan 24, 2010 3:23pm

    Oxygen Solutions

    40 posts

    page doesnt work at all :(, really appreciate your help

  • #9 / Jan 24, 2010 3:29pm

    Focus Lab Dev Team

    1129 posts

    AHHH typo! My apologies. I meant this:

    # force the www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ <a href="http://www.yourdomain.com/$1">http://www.yourdomain.com/$1</a> [R=301,L]
  • #10 / Jan 24, 2010 3:31pm

    Oxygen Solutions

    40 posts

    Perfect, Absolute legend!!!!!!!

    thanks so much for your help, ps just found your redirecthelper module and I love it!

  • #11 / Jan 24, 2010 3:42pm

    Focus Lab Dev Team

    1129 posts

    Sweet, glad it’s working 😊

    Glad you’re liking Redirect Helper too!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases