Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

htaccess redirect


Go to End


4 Posts   2869 Views

Avatar
Carol

Community Member, 2 Posts

10 November 2008 at 11:51pm

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?

Avatar
Liam

Community Member, 470 Posts

11 November 2008 at 5:37am

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.

Avatar
Carol

Community Member, 2 Posts

11 November 2008 at 6:13am

Thank you very much, it works perfectly.

Avatar
Howard

Community Member, 215 Posts

11 November 2008 at 8:32am

Another way to do this is add:

Director::forceWWW();

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