如何使用本地主机和主机服务器的 htaccess 从 url 中删除“/public"? [英] how can remove '/public' from url using htaccess for localhost and host server?
问题描述
我在 xampp 上使用 zend 框架 2.我在 root('htdocs/zendtest/.htaccess') 中创建了 .htaccess 文件,其中包含以下代码,
I'm using zend framework 2 on xampp. I created .htaccess file in the root('htdocs/zendtest/.htaccess') which has the following code,
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!
ZendMvcApplication::init(require 'config/application.config.php')->run();
当我在浏览器上打开localhost/zendtest"时,它会将我带到localhost/zendtest/public".我想通过仅设置 htaccess 来从 url 中删除public"(这将在本地主机和在线服务器中都有效)),不使用虚拟主机.我该怎么做?(localhost/zendtest/"目录中没有index.php"文件)
when I open 'localhost/zendtest' on browser then it takes me to 'localhost/zendtest/public'.I want to remove 'public' from the url by setting htaccess only(which will work both in localhost and online server),without using virtual host.how can I do that ?(theres no 'index.php' file in 'localhost/zendtest/' directory)
-谢谢.
更新:
目录:
我在zendtest/"文件夹中有以下 .htaccess(根据 Ravi Thapliyal 的回答)(现在在zendtest"文件夹中没有zendtest/index.php".只是 .htaccess.所有其他文件夹结构都是与目录"图片相同.)
I have the following .htaccess (according to Ravi Thapliyal's answer) in the 'zendtest/' folder (theres no 'zendtest/index.php' now in the 'zendtest' folder.just .htaccess. all other folder structures are same as the 'directory' picture.)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
但是现在在浏览器上打开'localhost/zendtest/'时出现以下问题-
but it has now the following issue when open 'localhost/zendtest/' on the browser-
已解决:
我不得不像下图那样做一些改变(.htaccess 很好):
I had to make some changes like the following picture (the .htaccess was good):
并实现了目标-
推荐答案
Change 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
中的规则.
I'm not sure what's zentest/public/.htaccess
trying to do but the above should rewrite /zentest
to /zentest/public
transparently. Now, it's up to your rules in public/.htaccess
and the index.php
there.
这篇关于如何使用本地主机和主机服务器的 htaccess 从 url 中删除“/public"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!