use*_*626 7 .htaccess zend-framework
我在xampp上使用zend framework 2.我在根目录中创建了.htaccess文件('htdocs/zendtest/.htaccess'),其中包含以下代码,
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} $ [NC]
RewriteCond %{HTTP_HOST} !/zendtest
RewriteRule ^(.*)$ /zendtest/public/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
我的'zentest/public/.htaccess'代码是,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
Run Code Online (Sandbox Code Playgroud)
'zentest/public/index.php'代码:
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
Run Code Online (Sandbox Code Playgroud)
当我在浏览器上打开'localhost/zendtest'然后它将我带到'localhost/zendtest/public'.我想通过仅设置htaccess(这将在localhost和在线服务器上都有效)从网址中删除'public',使用虚拟主机.我可以这样做吗?('localhost/zendtest /'目录中没有'index.php'文件)
-谢谢.
编辑:

更新:
目录:

我在'zendtest /'文件夹中有以下.htaccess(根据Ravi Thapliyal的回答)(现在在'zendtest'文件夹中没有'zendtest/index.php'.只是.htaccess.所有其他文件夹结构都与'目录'图片.)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
Run Code Online (Sandbox Code Playgroud)
但在浏览器上打开'localhost/zendtest /'时,它现在有以下问题 -

解决:
我不得不进行一些更改,如下图所示(.htaccess很好):

并实现了目标 -

更改 htdocs/zendtest/.htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么zentest/public/.htaccess尝试做,但上面的应该重写/zentest以/zentest/public透明.现在,这取决于你public/.htaccess和index.php那里的规则.