Htaccess: Rules for files in folders works but !

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
bunal
Forum Newbie
Posts: 1
Joined: Tue Oct 02, 2007 7:15 pm

Htaccess: Rules for files in folders works but !

Post by bunal »

Hi,

The below url works fine with my rule shown below.
http://www.domain.com/apple/abc.php

RewriteRule ^(.*)/(.*php)$ /view.php?id=$2&folder=$1

BUT

When i try the url http://www.domain.com/def.php i want to work as it work like above.
RewriteRule ^(.*php)$ /view.php?id=$1

Basicly if there is a folder it need to pass the foldername and the php page name to view.php. If there is no folder it should only pass the php page name.

I am trying for the last 2 hrs . Any help would be really appricated.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Htaccess: Rules for files in folders works but !

Post by superdezign »

Maybe you could just try making the folder portion of the regex optional. Instead of:

Code: Select all

RewriteRule ^(.*)/(.*php)$  /view.php?id=$2&folder=$1
Try:

Code: Select all

RewriteRule ^((.*)/)?(.*php)$  /view.php?id=$2&folder=$1
Post Reply