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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Problem with redirects of old URLs


Go to End


7 Posts   2008 Views

Avatar
Sophie

Community Member, 33 Posts

12 September 2009 at 11:22pm

Edited: 12/09/2009 11:23pm

I've been following the various suggestions for rewrites in the htaccess file. I want to direct old page to specific pages on my site. This is my htacces file. Can anyone advise me on what I'm doing wrong? These still direct me to "Page Cannot Be Found" just the way they did before I added the rewrite rule. This site is running 2.2.3.

Thank you!

RewriteEngine On
RewriteRule ^captainslog$ - [L]
RewriteRule ^captainslog/.* - [L] 
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]

RewriteRule index.html/ http://www.mysite.com/home/ [R=301,L]
RewriteRule links.html/ http://www.mysite.com/links/ [R=301,L] 

Avatar
socks

Community Member, 191 Posts

13 September 2009 at 6:40am

This is the syntax that I used:

RewriteRule ^links\.html$ /links/ [R=301,NC,L]
RewriteRule ^index\.html$ /home/ [R=301,NC,L]

Avatar
Sophie

Community Member, 33 Posts

13 September 2009 at 10:34am

socks,

I tried your syntax and this did not work either. Thanks for the suggestion!

Does anyone else have any other thoughts?

Avatar
bummzack

Community Member, 904 Posts

13 September 2009 at 11:04am

The syntax proposed by socks looks good to me. You just have to place your custom rewrite rules before the SilverStripe rules, since the SilverStripe rules will match all urls and further rules won't be processed.

A good place to put your custom rules is directly after the RewriteBase line.

Avatar
Sophie

Community Member, 33 Posts

13 September 2009 at 11:33am

Bingo! Thank you, banal!

Avatar
Bambii7

Community Member, 254 Posts

16 March 2010 at 3:31pm

Brilliant! real life saver here. I had my 40 or so 301 redirect in my .htaccess, went live with the new site. And I had a little panic attack. 301 didn't work but your rewrite rules rulz

Avatar
Mrfixer

Community Member, 49 Posts

10 May 2011 at 5:50am

+1, tried a few rewrite configs and could not get nothing to work (or it would work and append the old url), got panicky (well the client was with me at the time.. eek ..)

did a minutes searching and frantic re-writing while he made us a coffee, when he returned all was good..

many thanks @socks