views:

47

answers:

1

I have the following RewriteRule in my .htaccess to redirect from a friendly url to my main application file:

RewriteRule ^\/(.*).html$ home/www/page.php?p=$1 [L]

This should send any url that points to a html page to page.php with the url as a parameter that will be parsed by the app. This works for urls that look like http://www.example.com/hello.html

The problem is that I get a 404 error when the url contains a directory path, for example: http://www.example.com/category/hello.html

The error reads: "File does not exist: /home/www/category"

Seems it is first looking for the 'category' path instead of processing the .htaccess Any ideas how to solve this?

+1  A: 

Have you tried removing the initial \/ from your rewrite rule?

I just tried the following .htaccess file:

RewriteEngine On
RewriteRule ^(.*)\.html$ page.php?p=$1 [L]

With this as my page.php:

<?php print_r($_GET); ?>

And when I go to /category/hello.html I get the following:

Array ( [p] => category/hello )

Exactly as expected.

Also note that you need to escape the . before html, since you presumably don't want /category/hellozhtml to work.

Travis Brown