1

I have a blog which is at mysite.tld/blog. Currently mysite.tld redirects to mysite.tld/blog via an index.php in the root. Apparently when I set this up two years back I could not get the .httaccess file which is also in the root to work. On the filesystem, my blog is at /var/www/blog.

Now I create a simple website that I'd like to have show up at mysite.tld. It works via a PHP microframework which serves pages via an index.php file. I have this site in a git repo, and in this repo the index.php is located at www/index.php. I'd like to just have a clone of the repo on my server so I can just pull to update to a new version. So assuming I clone it as site in /var/www, the entry point ends up at /var/www/site/www/index.php.

I've spend the last 3 hours attempting to get this incredibly simple thing to work, to no avail. All I want to do is map URL /blog to /var/www/blog and the remainder of URL / to /var/www/site/index. What is the magical configuration I need for this?

Here is the output of lsb_release -a:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty

Here is the output of apache2ctl -V:

Server version: Apache/2.4.7 (Ubuntu)
Server built:   Jul 22 2014 14:36:38
Server's Module Magic Number: 20120211:27
Server loaded:  APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

Here is the output of apache2ctl -M:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
Giacomo1968
  • 58,727

1 Answers1

3

All I want to do is map URL /blog to /var/www/blog and the remainder of URL / to /var/www/site/index. What is the magical configuration I need for this?

You can easily do this with Apache’s Alias directive like this. Note that I see you are using Apache 2.4.7 which might have a slightly different syntax than Apache 2.2 and earlier which this advice is based on. But that said, while the syntax might be slightly different but the overall concepts are still the same and I am fairly confident Apache 2.4 still has Alias functionality.

These items would be set in your main site’s Apache configuration file which would be in /etc/apache2/sites-available/. Now they might be in a file named /etc/apache2/sites-available/default or in a separate file for the hostname like /etc/apache2/sites-available/mysite.tld so be sure to check your config before radically modifying the files.

This would set all requests to http://mysite.tld/blog to get content from /var/www/blog:

Alias /blog /var/www/blog

This would set all requests to http://mysite.tld/ to get content from /var/www/site/index:

Alias / /var/www/site/index

Now that said, you might only need the Alias /blog /var/www/blog; that second Alias / /var/www/site/index might not be needed as long as your DocumentRoot is set to /var/www/site/index.

A good, simple and concise overview of how Apache config setups work can be found on this site.

Giacomo1968
  • 58,727