7

我在 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 和在线服务器中都有效),没有使用虚拟主机。我该怎么做?('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]

但是现在在浏览器上打开“localhost/zendtest/”时出现以下问题-

在此处输入图像描述

解决:

我必须进行一些更改,如下图(.htaccess 很好):

在此处输入图像描述

并达到了目标——

在此处输入图像描述

4

2 回答 2

8

改变htdocs/zendtest/.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/

RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]

我不确定要做什么,但上面应该透明地重写zentest/public/.htaccess。现在,这取决于你的规则。/zentest/zentest/publicpublic/.htaccessindex.php

于 2013-10-26T12:35:22.100 回答
0

我所做的是为自己设置一个本地 Vhost,它可以通过 Firefox 访问。为此,我配置了 Vhost 并操作了我的 /etc/hosts 文件。

<VirtualHost *:80>
ServerName p120.local
ServerAdmin webmaster@localhost
DocumentRoot //var/www/tokam_dev/p120/public
        <Directory /var/www/tokam_dev/p120/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
SetEnv APPLICATION_ENV "development"
RewriteLog /tmp/p120-rewrite.log
</VirtualHost>

将 AllowOverride 设置为 All 并不是真正必要的,因为我可以将 .htaccess 内容复制到该 Apache vhost-config 文件中,但它可以更好地模拟生产环境。

于 2013-11-04T15:41:35.900 回答