4

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

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Ahmar Ali
  • 1,038
  • 7
  • 27
  • 52

2 Answers2

4

Use this rule in your Retailer/.htaccess file:

RewriteEngine on
RewriteBase /Retailer/

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
3

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!

Oleg
  • 7,070
  • 4
  • 47
  • 49