Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Custom htaccess redirect

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
Go to End
Author Topic: 1107 Views
  • le_banana
    Community Member
    21 Posts

    Custom htaccess redirect Link to this post

    Hello everybody

    I've got one question.
    Is there any possibility, to rewrite some SS URL adress in .htaccess file, from one to another?
    I've just want to add custom rule to htaccess without processing URL it with controller.
    For example:
    I've got URL like:

    where "realize" is SS URL, with some $_GET values, i'm working with. It works great.
    I'm trying to change this URL to something like this:

    I was trying add simple rule like:
    RewriteCond %{HTTP_HOST} ^www.mysite.com/object-spa/hotels$ [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/realize?choice=b2b&s=name[L,R=301]
    before line with patch to controller:
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    But it didn't work.

    I've also red some about Director class , and there was information, that i could add some rule into config.php file, but honestly, i didn't understand this doc well, and still don't know , how it exactly works.

    Is anybody know, how could i solve this issue? I'm new with SS, and i'm still learning, so i will appreciate any replies .

  • le_banana
    Community Member
    21 Posts

    Re: Custom htaccess redirect Link to this post

    Ok, let me ask something easier

    Suppose, i've got some external script, i want to mergre with SS application
    It is in main SS catalogue.

    What do i need to do in htaccess file , to see link like that:


    not like that:

    It's seems, every rule, 'i've added, was overrided by that line
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

  • banal
    Community Member
    901 Posts

    Re: Custom htaccess redirect Link to this post

    Well, your condition will never match, since your HTTP_HOST will not contain the whole url! You should use REQUEST_URI, like so:

    RewriteCond %{REQUEST_URI} object-spa/hotels$ [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/realize?choice=b2b&s=name[L,R=301]

    For your second question, you could do something like this (additional code highlighted):

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule script_file/?$ script_file.php [NC,L]
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

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.