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.

General Questions /

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

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

.htaccess - rewrite


Go to End
Reply


14 Posts   2903 Views

Avatar
Stijn

Community Member, 46 Posts

27 May 2010 at 12:33am

We recently changed our site to SilverStripe. But as we search with a keyword in Google, we still seeing a lot of old url's.

How can I change them. exp.:

/products.asp?productgroupid=5&language=nl to the /products?

I've seen a lots of posts where they suggest to work with a .htaccess file, but that doesnt work.

Avatar
ttyl

Community Member, 114 Posts

27 May 2010 at 3:16am

weird, I came here to ask the same question.

basically I want to do a redirect before the rewrite rule takes effect.

so if my old site was "mysite.com/old/page"

I want to first have that resolve to "mysite.com/new/page"

the way I see it there should be two steps

1) turn the request for "mysite.com/old/page" into a request for "mysite.com/new/page"

2) the htaccess rewrite rules takes "mysite.com/new/page" and performs as usual

how does one do this? surely there must be some sort of .htaccess voodoo to accomplish it?

Avatar
Stijn

Community Member, 46 Posts

28 May 2010 at 1:30am

Up ?

Avatar
banal

Community Member, 901 Posts

28 May 2010 at 2:15am

Just put the rewrite-rules before any SilverStripe rules, but after RewriteBase (if that exists in your setup).
Example:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^products.asp$ /products[R=301,QSA,L]

# SilverStripe Rewrites go here
</IfModule>

This will redirect products.asp to /products.. the QSA option tells the rewrite Engine to keep the query string (eg. ?productgroupid=5&language=nl)

Avatar
Stijn

Community Member, 46 Posts

28 May 2010 at 2:19am

Superb ! Thx!

Avatar
ttyl

Community Member, 114 Posts

28 May 2010 at 2:23am

Edited: 28/05/2010 2:24am

wow, I tried this numerous ways yesterday and never got it quite right. I'd have the wrong url with the right content, the right url with the wrong content, totally new weird urls that I didn't intend. anyway, this works, I owe you a beer!

QSA was what I was missing all along.

Avatar
Stijn

Community Member, 46 Posts

28 May 2010 at 2:32am

Should you still have a 404 error page in SilverStripe? Because I still got the 404 error page, even if I add that code in my .htaccess file

Avatar
ttyl

Community Member, 114 Posts

28 May 2010 at 2:37am

FYI, here is a useful tweak if you want to direct sub directories

RewriteRule ^old/(.*)$ /new/$1 [R=301,QSA,L]

so mysite.com/old/page now goes to mysite.com/new/page

easy peasy.

Go to Top