Zend Application from a subdirectory in which Zend links are correct

I installed the Zend application in a subdirectory. Don't ask why I just had to do it like this (not my preferred method), but I don't have that choice. The Zend application is located in the dsa subdirectory.

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 download the application. I can go to my root directories and other directories for other things without any problems.

In my application.ini application, I installed

 resources.frontController.baseUrl = "/dsa". 

In my layout.phtml file, if I have a var_dump 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 linked correctly. If you press F12 and look at them, you will get 404 not found for any file. What do I need to do to get the correct paths for displaying files. This is the first time I tried to install zend in a subdirectory, and obviously I am not doing something right. I have read everything I can find on this subject. Thanks for the help.

+4
source share
2 answers

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] 

These rules are equal:

RewriteCond %{REQUEST_FILENAME} -s [OR] # A request is a regular file with a size> 0 RewriteCond %{REQUEST_FILENAME} -l [OR] # A request to a file that is a symbolic link RewriteCond %{REQUEST_FILENAME} -d [OR] # RewriteCond %{REQUEST_FILENAME} -d [OR] Request to directory that exists

And if any of the above values ​​is true, the request is rewritten to public/index.php , which is incorrect. If the request is for a file that exists on disk, you DO NOT want to overwrite it; instead, you just want to serve this 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 means that if the request is for a file with a size> 0, a directory, or a symbolic link, then send the request to the actual requested file ( RewriteRule ^.*$ - ). If none of these conditions is true, rewrite the request to index.php.

In a separate note, I would like to go and completely get rid of the public directory. Take the contents of public and put them in /dsa . dsa now your public folder. You can store the application directory anywhere on the system, or if you need to put it in the dsa folder due to file system restrictions, be sure to add the rule to your .htaccess file, which prevents all access to the application . Then you just need to quickly make changes to the index.php file by specifying the correct path to the application using the APPLICATION_PATH constant.

I believe that these two changes should solve your problems.

+6
source

Try installing RewriteBase /dsa in your .htaccess.

0
source

Source: https://habr.com/ru/post/1402707/


All Articles