Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » htaccess redirect

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2173 Views
  • Carol
    Avatar
    Community Member
    2 Posts

    htaccess redirect Link to this post

    Hi, I wonder if anyone can help. I'm really quite new to all this so apologies if this is a stupid question. I have just set up a new website using SilverStripe, however my old website (which was just a wordpress blog) still has all its pages listed in the search engines under the non-www domain. I am attempting to put a 301 redirect in the htaccess file to redirect from non-www to www where this new site is, by adding the bit to the bottom of the file:

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

    RewriteEngine On
    RewriteBase /

    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 ###

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

    However, for some reason every time I now type in http://mydomain.co.uk I am redirected to http://www.mydomain.co.uk/sapphire/main.php?url=/ instead of just http://www.mydomain.co.uk. Can anyone help with what this sapphire directory is for, and perhaps what I am doing wrong for it to redirect to it?

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: htaccess redirect Link to this post

    Put the lines:

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

    Below this:

    RewriteEngine On
    RewriteBase /

    The redirect for the www issue has to come before the other redirect stuff.

  • Carol
    Avatar
    Community Member
    2 Posts

    Re: htaccess redirect Link to this post

    Thank you very much, it works perfectly.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: htaccess redirect Link to this post

    Another way to do this is add:

    Director::forceWWW();

    to your _config.php file, this works just as well

    2173 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.