我从这个post复制Zend的重写代码。如何将文档根据“移动”到公共目录一级?
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
它的想法是将文档根目录上一级的公共目录不接触或修改虚拟主机文件。
所以我在我的本地主机上的一个虚拟项目上测试它,看它是否在我的本地机器上运行。 但它不是。我仍然需要点击公共文件夹才能看到网页内容。
这是我的目录,
.htaccess
public/
.htaccess
index.php
的index.php,
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
而且我测试了我的生活的服务器上也是如此。重写代码根本不会将文档根级别移动到公共目录。
任何想法,我已经错过了?
我在我的Zend(Zend 2)项目上测试过,它也不能工作。而且我仍然需要点击公共文件夹才能看到网页内容。
任何想法?
编辑:/public/.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]
我不得不使用这个网址,看到网页,
http://{localhost}/a-project/public/
代替,
http://{localhost}/a-project/
它是活的服务器上一样,我必须使用
http://my-website.com/public/
代替,
http://my-website.com/
我认为的.htaccess根可以达到一个水平移动文档根到公共目录不接触或修改虚拟主机文件,但它不能明显...
你能告诉'/公/ .htaccess'的内容?还要澄清哪些网址无法使用? – anubhava 2015-04-01 19:46:07
@anubhava请参阅我上面的修改。 – laukok 2015-04-02 03:51:02