Web Tools

Moving the root of a site in a subdirectory

During the development of a site may be needed to move the root of site in a subdirectory of our web space. An example is the well-known laravel framework, which uses the public folder to accommodate the public file of the site.

To do this you have to configure the .htaccess file in the root of the web space.

.htaccess

The .htaccess files are text files that contain Apache directives for the configuration. These files work in a simple way. When Apache receives a request, before carrying it out, see if there is an .htaccess file in the folder of the addressed or in a previous folder, if it exists Apache reads and interprets it at run-time and configures it with the directives contained within that file. Apache reloads the file to every request, this allows you to change the configuration at any time at run-time. The scope of the .htaccess file is the folder where the file is located, and will affect all files and subdirectories within it.

Method

A) Create in your PC a file whit name .htaccess and copy the content below inside replacing mydomain.com with the domain of the site you want to change and subdirectory with the name of the folder to operate.

# www.nullalo.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change mydomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# 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 ^(.*)$ /subdirectory/$1
# Change mydomain.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.html, index.php, etc.
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ subdirectory/index.php[L]

B) Make a backup of the .htaccess file in the root of your website by copying it to a safe place.

C) Copy the file created in the root of your web space, if necessary force it to overwrite an existing file.

D) If there are problems you have to restore the previous file. In that case you will need to do a merge of the two files. This operation depend by your provider.

Previous post

TeslaCrypt: how to restore encrypted files

Next post

Windows: how to fix "Invalid file handle" error

Oscar Talamo

Oscar Talamo

No Comment

Leave a reply

Your email address will not be published. Required fields are marked *