homepage Welcome to WebmasterWorld Guest from 54.242.18.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
MultiViews and RedirectMatch not working together
trying to mask file extentions and redirect from a url without paramaters
tommyk




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

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.

site.com/product.php
becomes
site.com/product

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,
Tommy

 

coopster




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

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.

jdMorgan




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

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.

Jim

tommyk




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

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!

-Tommy

g1smd




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

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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved