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]
my 'zentest/public/.htaccess' code is,
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' code:
<?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();
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)
-thanks.
Edit:
Update:
directory:
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]
but it has now the following issue when open 'localhost/zendtest/' on the browser-
RESOLVED:
I had to make some changes like the following picture (the .htaccess was good):
and achieved the goal-
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…