Zend Application from Sub directory getting Zend layout links working correctly

后端 未结 2 790
礼貌的吻别
礼貌的吻别 2021-01-13 13:11

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

相关标签:
2条回答
  • 2021-01-13 13:28

    Try to set a RewriteBase /dsa in your .htaccess.

    0 讨论(0)
  • 2021-01-13 13:29

    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.

    0 讨论(0)
提交回复
热议问题