I have a URL https://facebook.****.in, set up to point at a directory /var/www/html/facebook_app. the virtual hosts file for this is /etc/apache2/sites-available/facebook.****.in.conf.

I would like to add a path to the URL which points to another custom directory such that,

https://facebook.****.in/apis    ->   /var/www/html/apis

I searched this forum and found some solution here

But I'm not sure where should i add the alias to? should it be the default.conf? or the facebook.****.in.conf file.

If it is facebook.****.in.conf file, how should i specify the alias? I would like to host it on 443 port for SSL.

facebook.****.in.conf file:

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    ServerName facebook.****.in
    ServerAlias facebook.****.in
    DocumentRoot /var/www/html/facebook_app/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


<VirtualHost *:443>

    ServerAdmin webmaster@localhost
    ServerName facebook.****.in
    ServerAlias facebook.****.in
    DocumentRoot /var/www/html/facebook_app/

    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on

    #   A self-signed (snakeoil) certificate can be created by installing
    #   the ssl-cert package. See
    #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
    #   If both key and certificate are stored in the same file, only the
    #   SSLCertificateFile directive is needed.
    SSLCertificateFile /etc/apache2/ssl/facebook_****_in.crt
    SSLCertificateKeyFile /etc/apache2/ssl/facebook.****.in.key
    SSLCertificateChainFile /etc/apache2/ssl/facebook.****.in.ca-bundle

here's the .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php

I have an index.php file which maps the url parameters to classes and methods.

  • Show us your config files, add them to the post. – Yaron Jul 24 '16 at 13:37
  • added config file. Please have a look. @yaron – cyberrspiritt Jul 24 '16 at 13:41
  • 1
    There are several options, first you can use ProxyPass, if this is another dir on the same machine you can symlink to it, the first option would probably be ProxyPass as explained here (useful for running services on different ports as a unified service): confluence.atlassian.com/doc/… – Yaron Jul 24 '16 at 13:53
  • saw it... can i know the symlink method? – cyberrspiritt Jul 24 '16 at 14:02
  • 1
    Thanx. That works @yaron – cyberrspiritt Jul 24 '16 at 14:23

You have to add the Apache Alias and Directory directives inside both VirtualHost sections that you have in your facebook.****.in.conf config file so it is enabled for both HTTP and HTTPS connections.

The snippet of configuration that you should add must be something like

Alias "/apis" "/var/www/html/apis"
# Now set directory permission 
<Directory "/var/www/html/apis">
     AllowOverride None
     Options -Indexes +FollowSymLinks

     <IfVersion < 2.3 >
         Order allow,deny
         Allow from all
     <IfVersion >= 2.3>
        Require all granted

I think that your Apache Server version is higher than 2.3, so only adding the Require all granted statement should be fine without checking for the version. I added it just in case though.

Also, I included some other directives for security and performance purposes. Please find below a quick overview of them

"For security and performance reasons, do not set AllowOverride to anything other than None in your block. Instead, find (or create) the block that refers to the directory where you're actually planning to place a .htaccess file."

  • Options -Indexes +FollowSymLinks: the -Indexes option will prevent the Web Server (the mod_autoindex module concretely) to return a formatted list of the directory when the required URL maps to a directory where there is no a DirectoryIndex (e.g. an index.html file). Apart from that, the +FollowSymLinks option allows the server to follow symbolic links in this directory. You can get more information about the Options statement and other available options in the Apache Web Server official documentation at http://httpd.apache.org/docs/current/mod/core.html#options

Also remember to set the correct permission to the /var/www/html/apis directory and files for the user that runs the Apache server (www-data in Ubuntu by default) and to restart the Apache service for changes to take effect.

sudo service apache2 restart


You can also include the DirectoryIndex directive into the Directory block in case you do not have an index.html file in that directory (e.g. index.php)

DirectoryIndex index.php

It is also possible to specify more than one file. In that case, the first file found will be returned

DirectoryIndex index.html index.php

More information about it at http://httpd.apache.org/docs/current/es/mod/mod_dir.html#directoryindex

  • This did not solve the issue. It is still picking up the document root as /var/www/html/facebook_app/ and opening up files in there. – cyberrspiritt Jul 27 '16 at 12:45
  • Also i would need Allow Override All to enable htaccess redirection in my codeigniter setup – cyberrspiritt Jul 27 '16 at 12:46
  • The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. I also added quotes to the Alias directive in my answer that I missed to include. Could you check it and try again? About AllowOverride, you can set it to All if you want to, but you can also try to set it to None and add the configuration in the htaccess file to the Directory block of config. Also remember to restart Apache for changes to be taken into account. – gongomgra Jul 27 '16 at 18:00
  • Tried as you suggested. It still points the document root as /var/www/html/facebook_app/ – cyberrspiritt Jul 28 '16 at 4:56
  • okay, I just checked... It is directing me to the folder. but due to some .htaccess issue, i'm only able to call the home controller, but not the methods in it. I believe htaccess might not be working. – cyberrspiritt Jul 28 '16 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.