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 and sub directories


Reply

2 Posts   1608 Views

Avatar
Eastside Sean

14 April 2009 at 1:09am Community Member, 4 Posts

Hi everyone,

I'm hoping this is a easy question with an easy solution but I'm not sure.

The scenario,

I've had to create a special page outside the CMS which is a bunch of hand coded HTML. This page is now uploaded under a directory called /stuff

What I've done is created a redirection page inside the CMS which redirects /stuff to /stuff/index.php

That all works fine and links as it's supposed to.. but it does look a bit ugly, because all the other pages are just /page1 /page2 etc and then I have /stuff/index.php in the URL bar.

I'm wondering, if it's possible to modify the htaccess file so that if someone hits /stuff, it bypasses the rewrite from SS and just lands on the directory (which will bring up my index.php file).

Thanks in advance!

Sean

Avatar
banal

14 April 2009 at 3:14am (Last edited: 14 April 2009 3:15am), Community Member, 901 Posts

Hi Sean

This is quite simple actually.

....
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
# Add the following line to your .htaccess file
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

This directive tells the rewrite engine to not perform a rewrite if the requested file is a directory. This applies to all directories however! If you just like to perform a rewrite from yourdir to yourdir/index.php, then add the following to your .htaccess

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/yourdir
RewriteRule .* yourdir/yourdir.php [L,QSA,NC]

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

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
...