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

Custom htaccess redirect


Reply

3 Posts   1116 Views

Avatar
le_banana

5 May 2009 at 2:59am Community Member, 21 Posts

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:

www.mysite.com/realize?choice=b2b&s=name
where "realize" is SS URL, with some $_GET values, i'm working with. It works great.
But:
I'm trying to change this URL to something like this:
www.mysite.com/object-spa/hotels

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 .
Thanks
Przemek

Avatar
le_banana

5 May 2009 at 8:02pm Community Member, 21 Posts

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:

www.mysite.com/script_file

not like that:
www.mysite.com/script_file.php

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

Avatar
banal

7 May 2009 at 6:17am Community Member, 901 Posts

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]
</IfModule>