Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

MultiViews and RedirectMatch not working together

trying to mask file extentions and redirect from a url without paramaters



3:38 am on Dec 5, 2008 (gmt 0)

5+ Year Member

Hello All:

I've been searching around the web all day looking for an answer to my problem. I just joined this forum, so excuse any newbie mistakes.

I'm working on a site where I want to mask the .php extension on the files. I successfully turned on MultiViews to do this.


The next problem is that the product.php file is useless without parameters. It is just a shell for showing items from the database. In order for a visitor to see anything the URL must have something like ?ID=123 at the end of it.

I want site.com/product to redirect to a page at site.com/products (note the plural) ONLY if someone tries to type in the former URL with no parameter.

With the line

RedirectMatch permanent database databases

in my .htaccess file, I get a 404 Not Found error on site.com/product - which makes sense because that file isn't actually there, but MultiViews should know to interpret it as site.com/products.php right?

So ultimately this is what I'd like:

site.com/product?ID=123 to continue working (as it currently is with MultiViews enabled)
site.com/product to redirect to site.com/products (both of which are .php files in actuality)

Any ideas?

Thanks so much,


2:23 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Welcome to WebmasterWorld, tommyk.

You cannot do both. You will need to edit the top of your php script to determine what URI was requested and send off the headers to redirect accordingly.


2:50 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Another solution is to disable MultiViews, and implement the needed features of MultiViews using mod_rewrite.

This is usually only a matter of rewriting extensionless URLs to add a file extension if the resulting URL resolves to a file that exists when that extension is added. Although this may sound difficult, it's actually only a two-line mod_rewrite rule.

For example:

# If extensionless page URL with ".php" added resolves to an existing file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# rewrite extensionless page URL to .php file
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.php [L]

In the RewriteRule pattern, the first subpattern matches zero or more directory levels, and the second matches only those URL-paths which do not contain a period or a slash in the final URL-path-part. This construct allows directory names to contain periods.



5:20 pm on Dec 5, 2008 (gmt 0)

5+ Year Member

Thanks for the replies. I thought I might have to do some of it in PHP, so I think I'll go that route.

Also, the alternative to MultiViews worked, so that is handy.

Thanks again!



8:30 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

If you are going extensionless, why still have parameters on the end?

Why not go for a "virtual folders" type of URL.


Featured Threads

Hot Threads This Week

Hot Threads This Month