htaccess redirect specified requests to subfolder

Viewed 24

My current htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain1.com$ [NC]
RewriteRule ^(.*)$ www/index.html [L,QSA]

RewriteCond %{HTTP_HOST} ^domain2.com$ [NC]
RewriteRule ^(.*)$ app/index.php?/$1 [L,QSA]

My problem:

I have several domains pointed to one hosting. Domain domain1.com should be pointed to www directory, domain2.com to app directory. In domain2.com all of request should be pointed to index.php except assets (images, styles, js and so on). Assets are also in app folder (or sub-directories), but as you can see all requests are pointed to index.php. I tried some of solutions from other questions but nothing work.

Example:

domain2.com/some/request/1/2 should be pointed to app/index.php
domain2.com/test.png should be pointed to app/test.png

Can you help me? Thanks a lot for your help.

1 Answers

I have read some pages, i cried and i finally create solution for my own problem.

If you want do something like this, you should create in root folder .htaccess file with:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/www [NC]
RewriteRule ^(.*)$ /www/$1 [L,NC,QSA]
Related