Author |
|
nutflakes
Joined: 13 Mar 2011 Posts: 2
|
Posted: Sun 13 Mar '11 19:18 Post subject: RewriteCond to check file existence in alias location |
|
|
Hi there,
I do really have problems to get the mod_rewrite configuration working properly... so hopefully you will help me out!
The whole thing is based on the following file system.
Code: |
project_1
private
public
index.php
project_2
private
test.php
public
|
I configured the vhost
Code: |
<VirtualHost 127.0.0.1>
ServerAdmin ...
ServerName domain.test
Options Indexes FollowSymLinks
DocumentRoot "D:\path\project_1\public"
Alias "/project_2" "D:\path\project_2"
<Directory "D:\path\project_1\public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
|
Now I am trying to set up the following rule.
If a file is called that is not available in my document root several other possible locations should be searched for the ressource and if found the redirect should occur and stop searching.
Let's see this example call
Code: |
Call: domain.test/bla.php
-> search for /project_1/public/bla.php
-> search for /project_1/private/bla.php
-> search for /project_2/public/bla.php
-> search for /project_2/private/bla.php
-> 404 if not found
|
To test the rules I used a hard coded path.
The following test-call works with the redirect to the given alias.
Code: |
RewriteRule ^(.*) /project_2/private/test.php [L]
|
But adding the condition to check the file existence first the rule is not executed any more. It seems to me that an alias in the condition is not taken...
Code: |
RewriteCond /project_2/private/test.php -f
RewriteRule ^(.*) /project_2/private/test.php [L]
|
How to get this search routine working without the possibility to check for existing files in an alias outside the document root?
I'm driving crazy with this
Any help is very welcome!
Thanks a lot
Regards from Munich,
Uwe |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 16 Mar '11 1:47 Post subject: |
|
|
Hi Uwe,
I'm not an expert in mod rewrite, but I've never seen a method / function that looks if a file exists or not.
So I would do that my application (php file) and a rewrite rule that redirects every request of a file or directory that doesn't exist in the filesystem to that dispatch file
e.g. for your vhost
Code: |
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
|
I guess it is easy for you in PHP do do that.
if you have any question or something else please ask again.
Best regards from Hamburg
Mario |
|
Back to top |
|
nutflakes
Joined: 13 Mar 2011 Posts: 2
|
Posted: Wed 16 Mar '11 12:00 Post subject: |
|
|
Hi Mario,
thanks for your reply.
First you should know that it is a Zend application and my solution is only required for local development. A build script will later create the final project structure that will get deployed to the different servers.
As our versioned project structure is split into several directories and components this mod_rewrite modification would be a big help for me.
This link will show how it is possible to get it working for two directories, but not for three.
Serving one Apache site from two parallel directories
The main problem I have is to get this alias file check working in my windows environment. Primarily this will help to locate and include missing images, js files and xml's. All the php includes can be extended to fit our needs.
Best regards,
Uwe |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 17 Mar '11 1:53 Post subject: |
|
|
Well in my example without that Alias inside the vhost a non existing directory or file would be rewritten to the index.php and added as path
e.g.
http://domain.test/project2/test.php would become
http://domain.test/index.php/project/test.php
inside index.php
Code: |
print_r(preg_split("{/}",$_SERVER["PHP_SELF"]));
|
output:
Code: |
Array
(
[0] =>
[1] => index.php
[2] => project2
[3] => test.php
)
|
Ok that is not a final script. But a good way to handle that. Even when it was multiple subfolders. |
|
Back to top |
|
Elan
Joined: 17 Jun 2011 Posts: 1
|
Posted: Fri 17 Jun '11 11:33 Post subject: RewriteCond to check file existence in alias location |
|
|
Hi nutflakes,
I am trying the similar scenario. When condition is given, the redirection is not happening. If condition is not given, then it is working fine. Below is the configuration.Is there anything else have to be configured??
D:/test/theme/.htaccess :
Code: |
Options +FollowSymLinks
RewriteEngine On
RewriteCond /test/theme/Bala/ -d
RewriteRule ^default/(.*)$ /test/theme/Bala/$1
|
httpd.conf :
Code: | Alias /test "D:/test"
<Directory "D:/test">
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory> |
|
|
Back to top |
|
crumpysale56
Joined: 15 Jul 2011 Posts: 2
|
Posted: Fri 15 Jul '11 12:05 Post subject: |
|
|
Well in my example without that Alias inside the vhost a non existing directory or file would be rewritten to the index.php and added as path. |
|
Back to top |
|