views:

472

answers:

2

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.

A: 

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/"&gt;
</head>

Further reading at http://www.w3schools.com/TAGS/tag%5Fbase.asp

David Caunt
A: 

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

Tomáš Fejfar