Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change document root using .htaccess on wamp

I have scratching my head over it for a long time now. Can't manage to get it to work. (I am a noob with apache that can be one reason also). Ok here is the problem in nutshell. I am using wamp and I have a directory Retailer. There is another directory inside it which is called public that contains the index and otherfiles. I want to make this public directory document root. I want to achieve this with .htaccess

My Rewrite module for apache is turned on.

Here is what I have tried:

RewriteEngine on
RewriteBase /public/
RewriteRule ^index.php$ test.php

And also I have tried

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^localhost/Retailer$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^localhost/Retailer$ 
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

And I have tried

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$ 
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

But result in all these cases is the same. That is: enter image description here

Any help will be appreciated Ahmar

like image 529
Ahmar Ali Avatar asked Mar 21 '23 18:03

Ahmar Ali


2 Answers

Use this rule in your Retailer/.htaccess file:

RewriteEngine on
RewriteBase /Retailer/

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
like image 132
anubhava Avatar answered Mar 23 '23 06:03

anubhava


You should config this not in .htaccess file but in apache config file httpd.conf:

<VirtualHost 127.0.0.1:80>
  DocumentRoot "/path/to/project/Retailer/public"  
  ServerName "retailer.local"
  ServerAlias "www.retailer.local" 
</VirtualHost>

Also you need to update your hosts file with the next line:

127.0.0.1 retailer.local

And restart your web server!

like image 32
Oleg Avatar answered Mar 23 '23 07:03

Oleg