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.

Redirect non-www to www and now www is getting error 404's

June 27, 2013 1:06pm

Subscribe [2]
  • #1 / Jun 27, 2013 1:06pm

    sgorton

    3 posts

    Redirect non-www to www and removed index.php?,  now www is getting error 404’s but non-www works 100%. If I flip www to non-www and remove index.php? then non-www gets 404’s and www works 100%.

    What is going on here?

    htaccess:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /

          RewriteCond %{HTTP_HOST} !^www\.(.*)
          RewriteRule (.*) http://www.%{http_host}/$1 [R=301,L]

          RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ /index.php?/$1 [L]

    I have removed the “?” from index.php, same results.
    I have changed [L] to [PT], same results.

    Also if this is posted in the wrong section would a mod please move to appropriate area?

  • #2 / Jun 28, 2013 1:36pm

    travisb

    172 posts

    Here’s an alternative to force www from html5 boilerplate htaccess that might work:

    # Option 2: rewrite example.com → <a href="http://www.example.com">http://www.example.com</a>
    # Be aware that the following might not be a good idea if you use "real"
    # subdomains for certain parts of your website.
    
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    RewriteRule ^ <a href="http://www.%{http_host}%{request_uri}">http://www.%{http_host}%{request_uri}</a> [R=301,L]

     

  • #3 / Jun 28, 2013 6:22pm

    sgorton

    3 posts

    Thanks for the suggestion. Still getting error 404’s on the http://www.domain.com with those changes, but domain.com works fine.

  • #4 / Jun 28, 2013 6:46pm

    sgorton

    3 posts

    ok, so I figured it out after 1 week of digging. I hope others find this post useful

    The big changes I made are different then what was suggest by the EE team.

    So I added index.php to the General Config on EE “Name of your site’s index page” = index.php.

    Then I added “DirectoryIndex index.php” to my .htaccess
    Then I added a command to add a slash to the end of any url

    And that is it. Completely works fine now, no errors on either http://www.domain.com or domain.com. Google Fetch is happy and that makes me happy.

    So here is my .htaccess file…if you use this be sure to remove http://www.domain.com and use your own domain, also if you are not redirecting to www you will have to use domain.com.

    Options +FollowSymlinks
    RewriteEngine On
    DirectoryIndex index.php

    #add slash to end URL
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_URI} !example.php
          RewriteCond %{REQUEST_URI} !(.*)/$
          RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]

    #www to non-www
    #    RewriteCond %{HTTP_HOST} ^www\.(.*)
    #    RewriteRule (.*) http://www.%{http_host}/$1 [R=301,L]
    #non-www to www
          RewriteCond %{HTTP_HOST} !^www\.(.*)
          RewriteRule (.*) http://www.%{http_host}/$1 [R=301,L]

    # Removes Index.php
          RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ /index.php?/$1 [L]

    I hope this helps someone else out there because I was so frustrated with this and not much help out there. I found a few crumbs here and there that finally lead me to this working fix. Although not what EE wants.

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

ExpressionEngine News!

#eecms, #events, #releases