.htaccess - 如何使用本地主机和主机服务器的 htaccess 从 url 中删除 '/public'?

标签 .htaccess zend-framework

我在 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

更新:

目录:

enter image description here

我在“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

已解决:

我不得不像下图那样做一些改变(.htaccess 很好):

enter image description here

并达到了目标——

enter image description here

最佳答案

更改 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/

相关文章:

zend-framework - Ubuntu Zend Framework cli securityCheck 错误

php - 当编辑器在 ajax 中加载时,tinymce getContent() 返回空字符串

php - Zend_Currency 的 Symbol 属性的最大长度是多少?

.htaccess 删除尾部斜杠

php - PHP 实现后 header 移位(UTF-8 BOM)

.htaccess - Yii 如何获得干净漂亮的 URL

php - .htaccess RewriteRule 500 内部服务器错误

mysql - 在 PHPMyAdmin 中查找子目录 WordPress 数据库

ajax - 发送 AJAX 响应时,如何使 Zend Framework 不呈现 View /布局?

PHP SOAP 客户端 至 WCF