Forum Moderators: phranque

Message Too Old, No Replies

reading a directory with php fails because of my bad .htaccess fu :(

.htaccess directory reading problem

         

ch1mp

8:16 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



hi all,

firstly, i've been using .htaccess to do rewrites for a while but to make search friendly urls with swfaddress and on flash sites. now i'm getting into making php stuff with haxe and i'm starting to need to get deeper into the mod_rewrite world...

my problem is this i have currently this as my .htaccess content...

RewriteEngine On
RewriteBase /realegest/
RewriteRule ^([^/\.]+)/?$ index.php?lang=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?lang=$1&mainSection=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?lang=$1&mainSection=$2&action=$3 [L]

which is all gravy as far as telling my app what to write to the browser as pages BUT, now a page which reads a directory of available files to download fails.

i think, and obviously i'm no expert that the opendir call in the php when requesting /realegest/downloads/subDirectory/ is having this rewritten as index.php?lang=downloads&mainSection=subDirectory which is obviously going to break it.

sooooo, after a google and a quick look around this forum i found some stuff about RewriteCond, and i added the following above the 3 rewriterules...

RewriteCond %{REQUEST_URI} !^/realegest/downloads

but no dice, anyone able to help me take the last step?

thanks in advance,

tom.

jdMorgan

11:01 pm on Feb 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your php is making HTTP requests, then correct it to access resources as *file reads* not HTTP requests.

If your php is not making HTTP requests, but directly reading files, then mod_rewrite in .HTaccess should not affect it at all -- The "HT" in .htaccess stands for "HTTP".

If this really were a .htaccess problem, I'd point you to RewriteCond and the "-d" test. But that's the right answer to a different kind of problem...

You should not need to use RewriteBase unless you've got an Alias defined in the server config.

Jim

ch1mp

10:27 am on Feb 16, 2010 (gmt 0)

10+ Year Member



thanks jdMorgan you helped a lot! i had gone through my app after cleaning up the urls to make them work with the rewrite rules, completely ignorant of this distenction between php reading resources on the server and them not being parsed by the http server apache. (i hope i haven't got that confused again).

the problem was with the path sent to the php which was wrong relative to the file accessing the directory.

thanks again, this is a great resource for apache i'm glad i found it and i'm sure i'll be back :)