php - How to set document root to be a subdirectory using .htaccess and not VHost -


on local machine following works perfect:

 <virtualhost *:80>        ##serveradmin postmaster@dummy-host2.localhost        documentroot "c:/xampp/htdocs/website_1"        servername testpage.com/website_1        ##serveralias www.recruitement.localhost        ##errorlog "logs/dummy-host2.localhost-error.log"        ##customlog "logs/dummy-host2.localhost-access.log" combined  </virtualhost> 

howerver im hosting website hosting company called justhost.com , not allow me modify httpd-vhosts.conf or httpd.conf. entire site coded files under website_1 reference other files under website_1 using simple slash "/" meaning website_1 treated document root. works on local machine when uploaded host gives me server errors because cant find files since trying locate files in public_html

for example:

  public_html       - website_1          - script.php          - style.css 

inside script.php:

<a href="/style.css">see style</a> 

this works on local machine on host fails since tries locate style.css under public_html , not public_html/website_1

is there way have multiple document roots without using vhosts? using .htaccess or else. please want try avoid rewriting code as possible since around 10 thousands lines of code.

enable mod_rewrite , .htaccess through httpd.conf , put code in .htaccess under document_root directory:

options +followsymlinks -multiviews # turn mod_rewrite on rewriteengine on rewritebase /  rewritecond %{document_root}/website_1/$1 -f [or] rewritecond %{document_root}/website_1/$1 -d [or] rewritecond %{document_root}/website_1/$1 -l rewriterule (?!^website_1/)^(.*)$ /website_1/$1 [r=302,l,nc] 

once verify working fine, replace r=302 r=301. avoid using r=301 (permanent redirect) while testing mod_rewrite rules.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -