Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » .htaccess - rewrite

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

Page: 1 2
Go to End
Author Topic: 2841 Views
  • Stijn
    Avatar
    Community Member
    46 Posts

    .htaccess - rewrite Link to this post

    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.

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: .htaccess - rewrite Link to this post

    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?

  • Stijn
    Avatar
    Community Member
    46 Posts

    Re: .htaccess - rewrite Link to this post

    Up ?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: .htaccess - rewrite Link to this post

    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)

  • Stijn
    Avatar
    Community Member
    46 Posts

    Re: .htaccess - rewrite Link to this post

    Superb ! Thx!

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: .htaccess - rewrite Link to this post

    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.

  • Stijn
    Avatar
    Community Member
    46 Posts

    Re: .htaccess - rewrite Link to this post

    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

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: .htaccess - rewrite Link to this post

    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.

    2841 Views
Page: 1 2
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.