Jump to:

558 Posts in 3589 Topics by 244 members

Hosting Requirements

SilverStripe Forums » Hosting Requirements » Issues with .htaccess and non www redirects

What you need to consider when choosing a hosting provider and plan.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1303 Views
  • Mrfixer
    Avatar
    Community Member
    49 Posts

    Issues with .htaccess and non www redirects Link to this post

    I have a SS site set up on a server with hostgator no problems at all, however this site will also contain another SS "Add on Domain" which is installed into the public_html folder as addondomain.com, the problem i am having is with the url rewrites from non www to www. this is what i have:

    Main domain:

    ### SILVERSTRIPE START ###
    <Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Files>

    <Files web.config>
    Order deny,allow
    Deny from all
    </Files>
    ErrorDocument 404 /assets/error-404.html
    ErrorDocument 500 /assets/error-500.html

    <IfModule mod_alias.c>
    RedirectMatch 403 /silverstripe-cache(/|$)
    </IfModule>

    <IfModule mod_rewrite.c>
    DirectoryIndex index.php
    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine On
    RewriteBase /

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

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    ### SILVERSTRIPE END ###

    in the add on domain htaccess:

    ### SILVERSTRIPE START ###
    <IfModule mod_dir.c>
    DirectorySlash Off
    </IfModule>

    RewriteEngine On
    RewriteBase /

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

    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    ### SILVERSTRIPE END ###

    as advised the rewrite conditions for non www to www are running below RewriteBase, but what is happening is for both domains the urls from non www do get rewritten but at the end of the url they are suffixed with .com/sapphire/main.php?url=/ this is for both domains, i also tried to force non www through via mysite _config.php but this has the same result.. any ideas? thanks

  • Mrfixer
    Avatar
    Community Member
    49 Posts

    Re: Issues with .htaccess and non www redirects Link to this post

    All sorted, originaly when installing the add on domain the main .htaccess file would thorw out a 500 error so i used a different kind of set up htaccess to get around this so i could install, thinking that the error would come back i left it as is, but actually the right thing was to have it with the same .htaccess that is in the add on domain folder... now all is hunky dory!

    1303 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.