Page 1 of 1

Htaccess: Rules for files in folders works but !

Posted: Tue Oct 02, 2007 7:16 pm
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.

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

Posted: Tue Oct 02, 2007 9:32 pm
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