ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

htaccess; adding index.php if not present

June 15, 2011 3:52pm

Subscribe [2]
  • #1 / Jun 15, 2011 3:52pm

    Cartegraph

    83 posts

    I know this is a bit of a weird request because usually you try to get rid of index.php but we cannot and I have the need to add in index.php if it isn’t present so that the link will still function.

    Make sense? I hope so.

    Thanks!

  • #2 / Jun 15, 2011 4:13pm

    Take any request…
    ... that doesn’t contain .css/js/jpg/png
    ... that doesn’t already contain index.php
    ... that isn’t a file
    ... that isn’t a directory
    ... and redirect to /index.php/[original request]

    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond $1 !index\.php [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [R=301,L]

    That’ll require a bit of testing to make sure it doesn’t break things, but, it should do the trick, or at least get you started…

    Edit: the RewriteCond $1 !index\.php [NC] line might be redundant; not sure if the !-f rule would catch that or not…

  • #3 / Jun 15, 2011 4:26pm

    Cartegraph

    83 posts

    Thanks for the quick reply! However I put this in my .htaccess file that is located at the root of the site and it does not work…

    example:

    http://www.cartegraph.com/solutions

    should redirect to

    http://www.cartegraph.com/index.php/solutions/

    any ideas as to why it wouldn’t work?

    Thanks!

    Edit: I am extremely unfamiliar with .htaccess. Is there a good place online to get familiar with it?

    Thanks!

  • #4 / Jun 15, 2011 4:50pm

    It wouldn’t work if /solutions is actually a directory on your server.

    Make sure you’ve got this near the top of your file too:

    RewriteEngine on
    RewriteBase /

    I devoted a morning to getting a better handle on .htaccess earlier this month and was glad that I did.  There were a few useful htaccess tips here, and this .htaccess cheat sheet was also cool.  I printed out a couple of examples and worked through them with a pen and made notes to figure out what they were actually doing.

    If you post the contents of your file I might be able to help.

  • #5 / Jun 15, 2011 5:07pm

    Cartegraph

    83 posts

    Awesome! Thanks for the links… seems i was missing the important part.

    RewriteEngine on
    RewriteBase /

    Thanks again!

    Lucas JD

  • #6 / Jun 15, 2011 9:10pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Nick.

    Lucas - If anything else comes up, please do let us know in a new thread..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases