0

I try to read many of the answer regarding htaccess but I could not find my way out. Image this architecture in webhosting: root/public_html/subfolder Now with the following code in htaccess file (placed in public_html) I can manage that when the domain is type in browser the visitor land in subfolder without digit example.com/subfolder, example.com is enough. It works. What I would like now is that the visitor will be redirect not in subfolder but in an "extrafolder" placed inside the root (level root that is the same level where the folder public_html is placed but not inside public_html). So how to modify this code:

# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subfolder/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ /subfolder/index.html [L] 

I try changing the /subfolder/ with ../extrafolder/ (supposing the double dot will push up one level) but does not work. Any idea? Thank you

Massimiliano Rubino
  • 279
  • 1
  • 2
  • 16
  • This is supposed to be 2 parts buzzle game, you just put the second part of it .htaccess configuration, but the first piece is the apache site configuration virtualhost, you can find it in /etc/apache2/sites-enabled/ if you are using Linux based system. If you need clear answer that may help you, you need to put the apache configuration too. – Ahmed Rashad Jun 06 '16 at 20:25
  • Thank you for answer me. I check but I don't have that file/folder in etc. I can eventually Create an Apache Handler. Any other idea? – Massimiliano Rubino Jun 07 '16 at 01:13
  • OK, I'll set that in answer. – Ahmed Rashad Jun 07 '16 at 18:10

1 Answers1

0

The current configuration you put is just working in case you put .htaccess inside the root folder of your website, which in this case is public_html, so no way to access another folder outside that root, except if you have directory alias.

In case you have access to change your apache configurations

You need to have the following steps to completely control the root of your website.

1- Yur apache virtual host configuration (this should be in /etc/apache2/sites-enabled/example.conf) should be something like the following:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/test
    <Directory /var/www/test/>
        DirectoryIndex index.php
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

3- You need to add this Alias /externalfolder/ "/var/www/test/externalfolder/" to the virtual host configuration above

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/test/public_html
    Alias /externalfolder/ "/var/www/test/externalfolder/"
    <Directory /var/www/test/public_html>
        DirectoryIndex index.php
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Now you can access that via http://example.com/externalfolder/file.php

Ahmed Rashad
  • 507
  • 3
  • 7
  • Thanks I found out that I have no access to apache virtual host configuration so the only think I can do is completely reverse the whole hosting: move the folder from the root in to the public and the folder in public to the root so I will have the visitors land in the folder I want... I could not think something better. Any last minute idea are appreciate anyway. – Massimiliano Rubino Jun 12 '16 at 05:42
  • No for sorry, I tried to find you a way to create directory alias in something like cPanel, but I couldn't find. – Ahmed Rashad Jun 12 '16 at 08:19