Forum Moderators: phranque

Message Too Old, No Replies

rewrite rule in case file not exist

         

MrBean

12:12 pm on Apr 6, 2010 (gmt 0)

10+ Year Member



hey

in my root directory that is only folders.
these days in my DirectoryIndex setting is

DirectoryIndex /newsite2006/index.php
this directory contains all the files i need and the user doesn't know that he surf on a subfolder

(for example if the user access to http://example.com/images/1234.jpg he actually goes to http://example.com/newsite2006/images/1234.jpg)

so far so good but, i built a new version of my site and it's located on /newsite2010/

i'm tring to make my server behave like that;

if you go to the root --> you'll see newsite2010/index.php

if you go to some other subdirectory --> if the directory doesn't exist on newsite2010/*somedirectory*/
check the newsite2006 directory

for example
http://example.com --> http://example.com/newsite2010/index.php

http://example.com/images/1234.jpg --> http://example.com/newsite2010/images/1234.jpg

http://example.com/images/blabla.jpg --> http://example.com/newsite2010/images/blabla.jpg (not found)-->
http://example.com/newsite2006/images/blabla.jpg

I hope I explained myself correctly

[edited by: jdMorgan at 2:58 pm (utc) on Apr 6, 2010]
[edit reason] Please use example.com only. [/edit]

jdMorgan

3:03 pm on Apr 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the RewriteCond directive in the Apache mod_rewrite documentation -- specifically the "-f" function.

RewriteCond %{DOCUMENT_ROOT}/newsite2010/<[i]requested-url-path[/i]> !-f

Here the "/<requested-url-path>" might be either the contents of %{REQUEST_URI} or it might be a back-reference (like /$1) to that path already matched and captured by your RewriteRule.

Jim

MrBean

7:49 pm on Apr 6, 2010 (gmt 0)

10+ Year Member



hey Jim thanks for your reply
I read the documention but I hardly undestood.
can you please leave an working example?

jdMorgan

8:50 pm on Apr 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Regrettably, we can't write your code for you here -- too many requests, and not enough 'helpers.' This is a discussion forum, as opposed to a "help desk."

However, specific questions are welcome, and the resources in our Apache Forum Charter and Apache Forum Library are free to all -- as is the site search function. Links to all are at the top of this page.

Please post your best-effort attempt at coding a solution as a basis for discussion.

Thanks,
Jim