Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can remove '/public' from url using htaccess for localhost and host server?

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!
Zend\Mvc\Application::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:

enter image description here

Update:

directory:

enter image description here

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-

enter image description here

RESOLVED:

I had to make some changes like the following picture (the .htaccess was good):

enter image description here

and achieved the goal-

enter image description here

like image 924
user1844626 Avatar asked Oct 26 '13 11:10

user1844626


1 Answers

Change htdocs/zendtest/.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/

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

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.

like image 62
Ravi K Thapliyal Avatar answered Sep 18 '22 14:09

Ravi K Thapliyal