我正在使用ZF2(Zend Framework 2,v2.2),我希望http://www.foo.com/path/to/app/重定向到公共文件夹。
我已经尝试了很多解决方案,但不是它们允许url指向/path/to/app/public/index.php,而只显示/ path / to / app /.
我很感激任何解决方案,因为我无法创建app骨架自述文件中描述的虚拟主机。
非常感谢任何帮助。
干杯, 格雷格。
答案 0 :(得分:5)
我找到了一个解决方案:https://github.com/gpfister/ZendSkeletonApplication
简而言之,我在应用程序的根目录中添加了一个.htaccess文件:
RewriteEngine On
# If URL to the application is http://foo.com/path/to/ZendSkeletonApplication/
# the set the base to /path/to/ZendSkeletonApplication/
RewriteBase /path/to/ZendSkeletonApplication/
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]
然后我更改了module / Application / config / module.config.php。
现在工作正常,但http://foo.com/path/to/ZendSkeletonApplication/public会失败,这很好,因为我不打算使用此网址访问该应用。
希望它有所帮助。
答案 1 :(得分:0)
如果你正在使用带有mod重写的apache将这个粘贴在公共文件夹(/ path / to / app)上方的htaccess中
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
答案 2 :(得分:0)
设置虚拟主机会不会更容易?
DocumentRoot "actual/path/to/application"
ServerName appname
这意味着当您输入
时http://yourdomain.com/appname it will resolve to http://root/actual/path/to/application
也许我没有正确理解问题 - 但我会使用VirtualHost而不是复杂的Mod_Rewrite规则。