0

My folder for public_html is /domain.com/public_html/ but i want the htaccess to redirect them to the folder /domain/public_html/www/ but still have domain.com as domain and not domain.com/www .

EDIT: I want the subfolder www in the public_html do be the default root and not public_html itself

Any solution on this?

Here is my current htacess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
    RewriteEngine On    
    RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
tagawa
  • 4,184
  • 1
  • 24
  • 34
Linus Odenring
  • 751
  • 1
  • 7
  • 9

2 Answers2

5

If you can only go for .htaccess, this simple one should do it;

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]

Explanation;

RewriteEngine on                      # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/    # Don't rewrite requests that are 
                                      # already to the /www/ directory. 
                                      # If this isn't here, we'll go into
                                      # a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA]      # Rewrite all else to the www subdirectory
                                      # QSA = keep the query string.

EDIT: Didn't see your existing htaccess, this (minus the redundant RewriteEngine statement) should probably go at the end instead of the whole IfModule block.

Joachim Isaksson
  • 163,843
  • 22
  • 249
  • 272
0

Try to put this in the htaccess on the public_html folder:

<IfModule mod_rewrite.c>
    RewriteEngine On    
    RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>

OR

Edit the apache configuration (httpd.conf)

vi /usr/local/apache/conf/httpd.conf

and set the DocumentRoot of the domain as

DocumentRoot /home/user/public_html/www

Save the file and restart the httpd service.

OR (recomanded)

Take a look at this question(and it's answer) - https://stackoverflow.com/a/5891858/1361042

EDIT

Use this HTACCESS:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/www/
    RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>

don't add it to yours but replace your htaccess with this one.

Community
  • 1
  • 1
Dan Barzilay
  • 4,430
  • 3
  • 25
  • 38
  • I tired the mod_rewrite solution you showed, but it just gives med error 500 and i can't acess httpd.conf because im on shared webhost. – Linus Odenring Oct 05 '12 at 12:25
  • if you can't access the httpd.conf file, than i'm affraid it is unpossible to change the default root directory. – Dan Barzilay Oct 05 '12 at 12:29
  • I have sended a message to my host(binero.se) and ask if it's possible to change it. Because it's a security reason when I going to have some other ppl acces the site throught ftp – Linus Odenring Oct 05 '12 at 12:34
  • I havn't seen your current htaccess, change it to my edit in my answer – Dan Barzilay Oct 05 '12 at 15:52