我在 xampp 上使用 zend 框架 2。我在 root('htdocs/zendtest/.htaccess') 中创建了 .htaccess 文件,其中包含以下代码,
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} $ [NC]
RewriteCond %{HTTP_HOST} !/zendtest
RewriteRule ^(.*)$ /zendtest/public/$1 [R=301,L]
我的 '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]
'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();
当我在浏览器上打开 'localhost/zendtest' 然后它带我到 'localhost/zendtest/public'。我想通过设置 htaccess 从 url 中删除 'public'(它可以在本地主机和在线服务器中工作),没有使用虚拟主机。我该怎么做?(“localhost/zendtest/”目录中没有“index.php”文件)
-谢谢。
编辑:
![enter image description here](https://i.sstatic.net/xJ4Ff.png)
更新:
目录:
![enter image description here](https://i.sstatic.net/FPzHF.png)
我在“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]
但是现在在浏览器上打开“localhost/zendtest/”时出现以下问题-
![enter image description here](https://i.sstatic.net/nPO4W.png)
已解决:
我不得不像下图那样做一些改变(.htaccess 很好):
![enter image description here](https://i.sstatic.net/jKx6t.png)
并达到了目标——
![enter image description here](https://i.sstatic.net/O2M5P.png)
最佳答案
更改 htdocs/zendtest/.htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
我不确定是什么
zentest/public/.htaccess
试图做但上面应该重写/zentest
至 /zentest/public
透明地。现在,这取决于您在 public/.htaccess
中的规则和 index.php
那里。
关于.htaccess - 如何使用本地主机和主机服务器的 htaccess 从 url 中删除 '/public'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19606329/