Change default project directory made in Zend 2

0

Hello everyone, 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 link and I am not using Apache Virtual Host, I am only using rewrite mode and .htaccess file

The problem:

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

It's like Zend has some place where I can set the root directory of the project.

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

NOTE: I would not like to use Virtual Host, because when I host the system in a host, they usually do not let you tweak the Apache settings.

The following is the .htaccess I'm putting into 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 it possible for both systems to use the same Zend, so that the Zend directory does not need to be redundant on ALL new systems. But that's not so important right now. I have an urgent need to resolve the previous item.

Thank you guys and remember that I'm a beginner on Zend so give me a little chewed explanation. (but in PHP I move to many years)

    
asked by anonymous 28.10.2016 / 22:20

1 answer

1

I solved the problem.

I'll post the solution here if 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 within 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 / 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's obvious that when you put in a valid domain the word localhost should be replaced by your domain.

My .htaccess from / public looks like this: (this already 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 ^(/.+)(.+)::$
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;)

    
03.11.2016 / 21:54