Zend Framework in a subfolder

十年热恋 提交于 2020-01-03 06:06:00

问题


I have installed a Zend Framework application in a subfolder, something like this:

www.mydomain.com/temp/zend-application/

Now the problem is all stylesheets, javascript files and also all links use relative paths, such as:

/css/styles.css
/js/jquery.js
/controller/action

And these go to the main domain like this:

www.mydomain.com/css/styles.css
www.mydomain.com/js/jquery.js
www.mydomain.com/controller/action

So how to make it work in that subfolder?

My .htacces file looks like this now:

RewriteEngine On

# Exclude some directories from URI rewriting
#RewriteRule ^(dir1|dir2|dir3) - [L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

EDIT: I have solved the problem by using setBaseUrl() method of front controller. Now the problem is how to edit my .htaccess file.


回答1:


The best solution would be to set a BaseUrl in your application. This should be detected automatically if you set a RewriteBase in your .htaccess. The router and other components have a knowledge of this setting and can generate appropriate links.

There's a view helper which makes linking to assets easier.

Alternatively you can fix those links with a tag in the document head.

<html>
<head>
<base href="http://www.mydomain.com/temp/zend-application/">
</head>

Further reading at http://www.w3schools.com/TAGS/tag_base.asp




回答2:


I would definetly use baseUrl() view helper preppended to the CSS's and JS's paths.



来源:https://stackoverflow.com/questions/1550840/zend-framework-in-a-subfolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!