.htaccess and URL rewrite question

Hi Guys,

I’m trying to create some modrewrite rules where any directory within my demo directory, will be redirected to page.php.

For example if I try to access, the following here’s the outcome I expect:

URL: http://www.mydomain.com/demo/about >>> http://www.mydomain.com/demo/page.php
URL: http://www.mydomain.com/demo/contact >>> http://www.mydomain.com/demo/page.php

Here’s the code I currently have:


RewriteEngine on
RewriteBase /demo
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /page.php [L]

It doesn’t work, any ideas whats wrong?

Zaggs,

It’s really the same thing I’ve whined about for the last couple of years (about WP’s mod_rewrite code) except that you are smart enough to have removed their <IfModule> wrapper.

In particular, I don’t like the use of RewriteBase as that affects your entire website (including your DocumentRoot). RewriteBase is designed to UNDO a mod_alias Redirect for mod_rewrite, not to change your DocumentRoot (as this would do).

The first RewriteRule is unnecessary (provided the WP index.php file is used in the redirection - it’s not) and the second RewriteRule MUST account for the lack of {REQUEST_URI} (http://www.example.com) with .? as the regex and /page.php is first checked in the server’s root then your DocumentRoot (it’s in the demo subdirectory). Finally, using something other than index.php as WP’s handler file is likely to cause some major problems (within WP), too.

How’s that for “any ideas what(')s wrong?”

Regards,

DK

Hi, thanks for your reply - but this isn’t a Wordpress site. This is a custom designed application.

Zaggs,

“Same difference.”

Regards,

DK