I have setup a Zend application in a sub directory. Dont ask why I just had to do it that way (not my preferred method) but I don't have that choice. The Zend application resides in a subdirectory called dsa.
http://dsa.dev/dsa
My .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ public/index.php [QSA,L]
This works and will bootstrap the application. I can go to my root directories and other directories for other things without any problems.
In my application.ini I have set
resources.frontController.baseUrl = "/dsa".
In my layout.phtml file if I var_dump the path it looks like this.
var_dump($this->baseUrl('css/main.css'));
http://dsa.dev/dsa/css/main.css
None of the links work, all css and js files are not linking correctly. If you hit F12 and look at them you get a 404 not found for any file. What do I need to do to get the correct paths to show the files. This is the first time I have tried setting zend up in a sub directory and obviously I'm not doing something right. I have read everything I can find on this subject. Thanks for the help.
At least one problem I see is that the rewrite rules in the .htaccess
file are incorrect.
Given these rules:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ public/index.php [QSA,L]
Those rules equate to:
RewriteCond %{REQUEST_FILENAME} -s [OR]
# The request is a regular file with size > 0
RewriteCond %{REQUEST_FILENAME} -l [OR]
# The request is to a file that is a symlink
RewriteCond %{REQUEST_FILENAME} -d [OR]
# The request is to a directory that exists
And if any of the above are true, the request is rewritten to public/index.php
which is not correct. If the request is for a file that exists on disk, you DO NOT want to rewrite it; instead you just want to serve that file.
The correct .htaccess
file should look something like this:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
This says, if the request is for a file with size > 0, a directory, or a symlink, then route the request to the actual file requested (RewriteRule ^.*$ -
). If none of those conditions are true, then rewrite the request to index.php.
On a separate note, I would go ahead and get rid of the public
directory altogether. Take the contents of public
and put them in /dsa
. dsa
is now your public
folder. You can store your application
directory anywhere on the system, or if you have to place it in the dsa
folder due to filesystem restrictions, make sure to add a rule to your .htaccess
file that denies all access to the application
folder. Then you just need to make a quick change to your index.php
file telling it the correct path to application
using the APPLICATION_PATH
constant.
I believe those two changes should fix your problems.
Try to set a RewriteBase /dsa
in your .htaccess.