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, Ed, biapar, Willr, Ingo, swaiba

Custom htaccess redirect

Go to End

3 Posts   1560 Views


Community Member, 21 Posts

5 May 2009 at 2:59am

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} ^$ [NC]
RewriteRule ^(.*)$[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 .


Community Member, 21 Posts

5 May 2009 at 8:02pm

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]


Community Member, 904 Posts

7 May 2009 at 6:17am

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 ^(.*)$[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]