How to set document root to be a subdirectory using .htaccess and not VHost
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews# Turn mod_rewrite onRewriteEngine OnRewriteBase /RewriteCond %{DOCUMENT_ROOT}/website_1/$1 -f [OR]RewriteCond %{DOCUMENT_ROOT}/website_1/$1 -d [OR]RewriteCond %{DOCUMENT_ROOT}/website_1/$1 -lRewriteRule (?!^website_1/)^(.*)$ /website_1/$1 [R=302,L,NC]
Once you verify it is working fine, replace R=302
to R=301
. Avoid using R=301
(Permanent Redirect) while testing your mod_rewrite rules.
Make a entry in a .htaccess. Suppose you have a website abc.com. You want to run another website in directory. Then create a .htaccess in parent directory pointed to abc.com
RewriteEngine onRewriteCond %{HTTP_HOST} ^abc.com$ [NC,OR]RewriteCond %{HTTP_HOST} ^www.abc.com$ RewriteCond %{REQUEST_URI} !subdirectory/RewriteRule (.*) /subdirectory/$1 [L]
Rewriting all image requests to root could be a solution. You may try this in one .htaccess file at root directory:
Options +FollowSymlinks -MultiViewsRewriteEngine OnRewriteBase /# Check if request is for an image at root. Add/remove file types if necessary.RewriteCond %{REQUEST_URI} ^/([^.]+)\.(png|jpg|gif|css) [NC]RewriteCond %{REQUEST_URI} !/website_1 [NC]# Rewrite request to point to "website_1" directoryRewriteRule .* /website_1/%1.%2 [L,NC]