Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » htaccess and sub directories

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: 1596 Views
  • Eastside Sean
    Avatar
    Community Member
    4 Posts

    htaccess and sub directories Link to this post

    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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: htaccess and sub directories Link to this post

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

    1596 Views
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.