Title: [PULL REQUEST] Add support for Apache alias
Last modified: August 21, 2016

---

# [PULL REQUEST] Add support for Apache alias

 *  [Tobias Nyholm](https://wordpress.org/support/users/tnyholm/)
 * (@tnyholm)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/pull-request-add-support-for-apache-alias/)
 * I cant really do a pull request with SVN but here is some modifications.
 * **Issue: **
    I got a website at in _/var/www/website_ that is executing when 
   ever I access [http://www.domain.com/](http://www.domain.com/). I got a wordpress
   blog in _/var/www/wordpress_. I’ve configured Apache with an alias like
 *     ```
       Alias /site "/var/www/wordpress"
       <Directory "/var/www/wordpress">
             AllowOverride All
             Allow from All
       </Directory>
       ```
   
 * There are two problems with the plugin when running this setup.
    #1 w3_get_document_root()
   and w3_get_home_root() are returning blank strings #2 RewriteBase is misconfigured
   for the minify/.htaccess
 * **Solution: **
    I made some changes to the functions named in #1.
 *     ```
       function w3_get_document_root() {
           static $document_root = null;
           $len = strlen($_SERVER['PHP_SELF']);
           $split = $len/2;
   
           if ($document_root === null) {
               if (!empty($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == $_SERVER['PHP_SELF']) {
                   $document_root = w3_get_site_root();
               } elseif (!empty($_SERVER['DOCUMENT_ROOT'])) {
                   //get the script path without the HOME
                   $phpSelf=str_replace(w3_get_home_path(), '',w3_path($_SERVER['PHP_SELF']));
   
                   $document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen($phpSelf));
               } elseif (!empty($_SERVER['PATH_TRANSLATED'])) {
                   $document_root = substr(w3_path($_SERVER['PATH_TRANSLATED']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
               } elseif (!empty($_SERVER['DOCUMENT_ROOT'])) {
                   $document_root = w3_path($_SERVER['DOCUMENT_ROOT']);
               } else {
                   $document_root = w3_get_site_root();
               }
   
               $document_root = realpath($document_root);
               $document_root = w3_path($document_root);
           }
   
           return $document_root;
       }
   
       function w3_get_home_root() {
           if (w3_is_network()) {
               $path = w3_get_base_path();
           } else {
               $path = w3_get_home_path();
           }
   
           $root = w3_get_document_root();
           $home_root = $root . $path;
           $home_root = realpath($home_root);
           if($home_root === false){
               $home_root=$root;
           }
           $home_root = w3_path($home_root);
   
           return $home_root;
       }
       ```
   
 * To address the problem in #2 if rewrote the rules_core_generate_apache() function.
 *     ```
       function rules_core_generate_apache($config) {
               $is_network = w3_is_network();
   
               $base_path = w3_get_base_path();
               $home_path = w3_get_home_path();
               $rewrite_base = ($is_network ? $base_path : $home_path);
               $rewrite_base=rtrim($rewrite_base,'/');
   
               $cache_dir = w3_filename_to_uri(W3TC_CACHE_MINIFY_DIR);
               $minify_filename = w3_make_relative_path(W3TC_DIR . '/pub/minify.php',
                   W3TC_CACHE_MINIFY_DIR);
   
               $engine = $config->get_string('minify.engine');
               $browsercache = $config->get_boolean('browsercache.enabled');
               $compression = ($browsercache && $config->get_boolean('browsercache.cssjs.compression'));
   
               $rules = '';
               $rules .= W3TC_MARKER_BEGIN_MINIFY_CORE . "\n";
               $rules .= "<IfModule mod_rewrite.c>\n";
               $rules .= "    RewriteEngine On\n";
               $rules .= "    RewriteBase " . $rewrite_base.$cache_dir . "/\n";
               $rules .= "    RewriteRule /w3tc_r
       /* some more code.. */
       ```
   
 * **Disclaimer: **
    This pull request is not ready to merge (since public unittests
   do not exist). I have not tried this solution in any other server configuration.
 * [http://wordpress.org/plugins/w3-total-cache/](http://wordpress.org/plugins/w3-total-cache/)

Viewing 1 replies (of 1 total)

 *  [yenerguller](https://wordpress.org/support/users/yenerguller/)
 * (@yenerguller)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/pull-request-add-support-for-apache-alias/#post-4171228)
 * Tobias your solution worked for me also, thank you!

Viewing 1 replies (of 1 total)

The topic ‘[PULL REQUEST] Add support for Apache alias’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

## Tags

 * [alias](https://wordpress.org/support/topic-tag/alias/)
 * [apache](https://wordpress.org/support/topic-tag/apache/)
 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)

 * 1 reply
 * 2 participants
 * Last reply from: [yenerguller](https://wordpress.org/support/users/yenerguller/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/pull-request-add-support-for-apache-alias/#post-4171228)
 * Status: not resolved