Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond -f for files in subdir

rewritecond subdir file exists

         

bitseeker

1:30 pm on Mar 2, 2007 (gmt 0)

10+ Year Member



Hi forum,

i do have a problem with mod_rewrite.

I have a multi language homepage, where the different files are located in subdirectories /ger and /engl .
Now what iīve done is that i want to redirect everything behind the URL to the subfolder /ger if itīs not a file.


RewriteEngine On
RewriteBase /ger
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php [R=301,L]

This works fine.

But how can i check if a certain file exists in the subdirectory /ger?
When i enter [mydomain.org...] (p_solenoids.php DOES exist in /ger/) i want apache to check if p_solenoids.php exists in /ger and then redirect to this file.

i tried adding following before the above RewriteCond:


...
RewriteCond ger/%{QUERY_STRING} -f
RewriteRule ^(.*)$ /ger/%1 [L]
...

but this doesnīt work. I end up in /ger/index.php

Can anyone give me a hint, whatīs wrong? I also tried {REQUEST_FILENAME}, but this is the absolute filepath, i canīt use for my purpose.

thx

jdMorgan

2:50 pm on Mar 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like:

RewriteCond %{DOCUMENT_ROOT}/ger%{REQUEST_URI} !-f

(I am not sure about whether the slash preceding "/ger" will be needed -- try it with and without.)

Jim

bitseeker

1:10 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



Jim,

thanks a lot. Your solution was absolutely perfect. Btw, the preceding slash was neccessary.

thanks again, Olli