View Full Version : .htaccess for forcetype method giving 500 server error

07-07-2008, 05:25 PM
This is really annoying, I'm sure it's something stupid I've done. If anyone can spot anything I've missed, or just plain overlooked then it would be appreciated. Thanks;

I've just done this site and thought I'd try using the forcetype method to generate more SEF URL's. I wish I hadn't now.


I want it to work when I go to http://durban.directrouter.com/~espressso/ethics/

It should, but doesn't

My htaccess file;

<files index>
RewriteEngine on

RewriteBase /

# remove .php and THE_REQUEST to prevent loops

RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP

RewriteRule (.*)\.php$ $1 [R=301]

# remove trailling slash

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} /$

RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteCond %{REQUEST_URI} !/$

RewriteRule (.*) $1\.php



07-08-2008, 06:25 PM
OK, so I found out that my host didn't have mod_rewrite turned on, well, they said they did, but it actually wasn't working. They recompiled Apache and it started working!

I now have the following in my .htaccess file;

# initialise rewrite and set base

RewriteEngine On
RewriteBase /

# strip index.php if requested

RewriteRule ^(.*)\.php$ http://durban.directrouter.com/~espresso/ [R=301]

RewriteRule ^(.*)\.php?page=([a-z]+)$ /$1/ [R=301]

It's working well now and when you request index.php, you get redirected to the root ( / ) which is what I wanted, so I have now hidden what file type I'm using.

The next step is to take any argument passed through the URL (index.php?page=ethics), It would be ?page=ethics in this example.

I want to redirect so it looks like this


I thought the following line would accomplish this;

RewriteRule ^(.*)\.php?page=([a-z]+)$ /$1/ [R=301]

But apparently it's not that simple (I'll walk through it, if anyone spots anything, feel free to shout up!);

^ - Start of expression to be matched
(.*) - Wildcard, anything
\ - used to escape the dot before the file extension
.php - the file type I want to match
?page= - This is included in the URL
([a-z]+) - Any character from a to z
+ - any amount of iterations of a-z
$ - end of expression to be matched

/$1/ - redirect to part in square brackets(with slashes before and after)
[R=301] - 301 redirect mode

Anyone see what's wrong? Probably something stupid, I've never done this before, so please be gentle.