How to Access an outside folder in Localhost
By default, localhost uses the htdocs folder, but we want it to use a specified folder inside of our dropbox called www.
We will achieve this by using an alias.
First, open httpd.conf; you can find this in \xampp\apache\conf
or in the XAMPP Control Panel
located in the Apache row, click Config
then Apache (httpd.conf)
.
Now, locate the <Directory>
tag that should looks something like this;
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
# important content
</Directory>
You will want to copy the entire Directory tag and paste it below, then change the path to your specified folder like so
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
# important content
</Directory>
<Directory "C:/your_path/">
# important content
</Directory>
Eg. <Directory "C:/Users/ash/Dropbox/www">
Now, let's scroll down and find <IfModule alias_module>
then locate and copy Alias /webpath /full/filesystem/path
, then locate ScriptAlias /cgi-bin/ "C:/xampp/cgi-bin/"
and paste below like so
ScriptAlias /cgi-bin/ "C:/localservers/xampp/cgi-bin/"
Alias /webpath /full/filesystem/path
Now change the Alias to /your_folder /your_path
Eg. Alias "/www" "C:/Users/ash/Dropbox/www"
.
Save and close, then restart Apache.
Now you can access, localhost/your_folder
Eg. localhost/www
But Wait! What if you wanna access your folder with just localhost
How to change the default location using PHP
Inside of htdocs let's create an index.php or if one already exist, replace or edit it.
Then add the following snippet and change /your_folder/
to your specified folder.
<?php
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/your_folder/');
exit;
?>
Eg. header('Location: '.$uri.'/www/');
Save and close, then restart Apache.
Now go to localhost and it should automatically redirect to localhost/your_folder
and you're all set!
Top comments (0)