Change default project directory in Zend 2

Asked

Viewed 180 times

0

Hello folks this is my first post :D

I’m new to Zend framework and I’m using Zend 2 + PHP 5.5 + Mysql + Apache

I have the system on my server running through the address http://localhost and I am not using Apache Virtual Host, I am using only rewrite mode and file . htaccess

The problem:

  • I want to put another NEW system on the same server where it could be accessed through localhost/system1 and localhost/system2 however every change I try to open the system, but when I try to access the menus it always tries to use the address localhost and not localhost/system1.

It’s like Zend has some place where I can configure what the project’s root directory is.

And even if I do not use the menus and directly type the url it tb does not work. I am using Zend Navigation for menus.

OBS.: I would not like to use Virtual Host, because when I go to host the system on a hosting usually they do not let you touch the settings of Apache.

Follow the . htaccess I’m putting inside localhost/system1 :

# Turn on rewrites.
RewriteEngine on

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?localhost$

# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/public/

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ public/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?localhost$
RewriteRule ^(/)?$ public/index.php [L]
  • I would like to make the two systems use the same Zend if possible, so that the Zend directory does not have to be redundant in ALL new systems. But that is not so important now. I have urgent to resolve the previous item.

Thank you guys and remember I’m new to Zend so give a little chewed explanation. (but in PHP I move for many years)

1 answer

1


I was able to solve the problem.

I will post here the solution in case someone goes through the same problem in the future.

The solution was through the . htaccess file, I added at the end of the file:

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

With this any request made inside the directory /system1 or /system2 will be redirected to the public directory.

Inside public has another . htaccess that already comes with the Zend Skeleton, which makes everything else happen.

My . htaccess from the /system1 directory looks like this:

# Turn on rewrites.
RewriteEngine on

## Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?localhost$
#
## Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/public/
#
## Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#
## Rewrite all those to insert /folder.
RewriteRule ^(.*)$ public/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?localhost$
RewriteRule ^(/)?$ public/index.php [L]

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

It is obvious that when you put in a valid domain the word localhost should be replaced by its.

Already my . htaccess of /public was like this: (this comes in Zend)

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

Well, thank you very much and now with this solution maybe I can even put in a hosting that I use in Locaweb ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.