views:

31

answers:

2

I'm sure this is probably really simple, but my knowledge really isn't good in this area, and I don't seem to be able to get it right.

I have the following file structure:

/cms (renamed from system)
cms.php (renamed from index.php, added to DirectoryIndex in .htaccess)
.htaccess
index.html
page1.html
/css
/js

I also have the .htaccess from the CI wiki. The part I think needs adjusting is:

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to cms.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ cms.php?/$1 [L]

I want most files that already exist to be accessible, e.g. and .js, .css, .png, .swf etc, but any .htm or .html to be processed by cms.php.

For example, if the user requests http://localhost/index.html, index.html gets passed to cms.php, or if http://localhost/dir/page.html is requested, dir/page.html is passed.

A: 
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(*\.js|*\.png|*\.css|*\.swf|folder1|folder2)
RewriteRule ^(.*)$ index.php/$1 
RewriteRule ^.\.htm cms\.php
RewriteRule ^.\.html cms\.php
</IfModule>

you can add other extensions and/or folders that you do not want re-directed to the RewriteCond line.

stormdrain
Ah, ok. Is there a way to reverse it, so I specify which files should be rewritten (.htm, .html)?
Josh
Yes. You can add additional `RewriteRule` lines to the file. I edited the answer with 2 examples of additional rewrite rules that will redirect `.htm` and `.html` files to `cms.php`.
stormdrain
Hmm, couldn't get it to work properly. However, I think I've sorted it - found a tutorial on it, and came up with RewriteRule ^(.*\.html)$ cms.php?/$1 [NC] which seems to do the job. Thanks anyway!
Josh
A: 

Found a tutorial, and came up with the following:

RewriteRule ^(.*\.html)$ cms.php?/$1 [NC]

So anything requested ending in .html is passed to cms.php, resulting in a URL like cms.php/index.html, which cms.php can process and output.

Josh