mod_rewrite user friendly urls

Permalink
Hi everyone

I have been trying to get C5 to rewrite my URLs to something nicer.

I have activated the Pretty URLs at the Dashboard and copyied the text to my .htaccess file.
All of this works just fine.

However I would like to have each and everyone of my pages generated so that it comes with the extension of .php or .html (the last one is preferred)

I have tried doing this by reading up on some mod_rewrite but nothing seems to happen?

I am running Version 5.4.0.5 on a localhost and mod_rewrite is enabled and working...

This is my .htaccess file right now:
# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /concrete/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
</IfModule>
# -- concrete5 urls end --

But all it does is saying:
"Object not found!
The requested URL was not found on this server.
"

Can anyone help me?

//Carsten - Denmark

sabumnimdk
 
jaredquinn replied on at Permalink Reply
jaredquinn
Your .htaccess file should not have the PHP open/close tags in there.

You should also confirm that you are running on Apache (or another webserver that supports .htaccess). I've recently had to deploy a site to a Zeus webserver which uses it's own style re-write language.

If you are running Apache - you need to have mod_rewrite loaded for it to work.

Or your web site isn't allowing override's in the form of .htaccess due to some configuration directive.

cheers,
jared
nteaviation replied on at Permalink Reply
nteaviation
I'm not sure you want the "/" slash in there. That is going to take:

xxxxx.php
and change it to
/xxxxx.html

Right?
nteaviation replied on at Permalink Reply
nteaviation
I'll answer my own question... WRONG! LOL... Ok, The way I understand it, the 2 ReWriteCond say that if it is NOT a file or directory, then contine processing the ReWriteRule, so

xxxx.php is a file so the first ReWriteCond fails and ReWriteRule never gets to run... I think that makes sense :)
jaredquinn replied on at Permalink Best Answer Reply
jaredquinn
Oh. I didn't notice the error with the php -> html rewriting there. So...

Try this one:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [L]
RewriteRule ^(.*)(\.html|\.php)$ $1 [R=301,L]
RewriteRule ^(.*)$ index.php/$1 [L]


Description:

Any file (that doesn't exist) with a .html or .php ending will be given a 301 redirect to the page without (better for SEO) and then index.php will be used normally.

You can remove the R=301 if you don't want to redirect and just serve the pages up with .html and .php endings, but I personally prefer the redirect.

cheers,
jared