我已经使用ZendFramework2完成了我的第一个web应用程序,我即将将它放到网上。但万维网主机不允许我改变我的vhost配置!允许使用.htaccess文件。
公用文件夹中的.htaccess文件如下所示:
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]我的文件夹目录结构如下:
-ProjectName
-config
-module
-vendor
- zendframework
-public
- css
- img
- JS
- index.php Index.php文件:
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run(); 因此,我的问题是:如何设置我的ZF2应用程序只使用.htaccess文件?
另外,我想在我的站点www.example.com运行时调用默认的“前沿”模块调用。
您的回答将不胜感激。提前谢谢。
发布于 2014-01-27 03:36:32
您似乎需要启用mod_rewrite模块并重新启动Apache。
Zend 2要求启用Apache的*mod_rewrite*模块。*mod_rewrite*模块用于根据某些规则重写请求的URL,将站点用户重定向到另一个URL。
Debian中的或Ubuntu
要启用Apache mod_rewrite模块,请键入以下命令:
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/rewrite.load ./rewrite.load
上面的命令在mods-enabled目录中创建了一个符号链接,这样就可以在Apache服务器的现代版本中启用模块。
最后,重新启动Apache服务器以应用您的更改。
Linux中的符号链接类似于I>中的快捷方式。
Fedora中的、CentOS或Red
在这些Linux发行版中,默认情况下mod_rewrite是启用的,因此您不需要做任何事情。
重新启动Apache服务器
编辑配置文件后,通常必须重新启动Apache才能应用更改。您可以使用以下命令(在Debian或Linux中)执行此操作:
sudo service restart apache2
或以下内容(在Fedora、CentOS或Red中):
sudo service restart httpd
因此,您应该看到输出如下所示:
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified
domain name, using 127.0.0.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully
qualified domain name, using 127.0.0.1 for ServerName [OK]https://stackoverflow.com/questions/20858591
复制相似问题