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

htaccess and sub directories

Go to End

2 Posts   1916 Views

Eastside Sean

Community Member, 4 Posts

14 April 2009 at 1:09am

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!



Community Member, 904 Posts

14 April 2009 at 3:14am

Edited: 14/04/2009 3:15am

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