Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Seeking Wordpress-Apache conf that allows for dynamic subdir-to-site creation. Specifically, want to create any of these /var/www subdirs on the fly:

/var/www/main
/var/www/siterev1
/var/www/siterev2

and place a WordPress install in each one (easily done with git branches), and have above installs/dirs/sites map, respectively, to the following:

http://my.com/main
http://my.com/siterev1
http://my.com/siterev2

...all without any changes to Apache conf as subdirs are added. (eg: adding /var/www/siterev3 would enable http://my.com/siterev3 without any Apache conf changes.) This is a rather std config for Apache-to-dir path mapping, but can't get it to work, and am guessing the Apache mod_rewrite config (in Apache config below, comes form "std" WordPress install instructions) is not flexible enough.

Answers like this hard-code the site/path/subdir name in the Apache conf. Want to avoid this. Alternatively, if we must hard-code Apache conf, we'll go there (begrudgingly), but don't even know how to do that.

Current Apache config follows (running on Ubuntu 11.04 or above). Have tried a few tweaks gleaned from other posts/answers, but nothing's yet worked (and most configs appear to hard-code the subdir/site references).

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
share|improve this question
    
Additional discussion at wordpress.org. –  Johnny Utahh Feb 20 '12 at 2:56
add comment

1 Answer

I would try something like this. It may need a bit of tweaking as I'm used to putting mod_rewrite config in the server/VirtualHost context, not in a <Directory> block, but the idea should hopefully be clear enough.

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    # Put all the mod_rewrite rules in the Directory where the actual
    # web content is found, not in <Directory />
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        # Let through any access to index.php - can tweak this to only
        RewriteRule ^.*/index\.php$ - [L]

        # Grab the first component of the requested path, then use that in the
        # RewriteRule substitution. So e.g. fish/saltwater/shark.php ends up
        # internally redirected to fish/index.php, and animals/cats/tiger.php
        # is rewritten to animals/index.php - without naming either of the
        # directories in the rule.
        #
        # N.b. the regular expression in the RewriteRule roughly means "all the
        # characters before the first forward slash in the request path", which
        # should grab the subdirectory name.
        #
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([^\/]+)/.*$ $1/index.php [L]
    </IfModule>
</Directory>
share|improve this answer
    
Thx. Can't yet get it to work (tweaks, etc). Getting "the page doesn't exist" feedback from WP when visiting pages. Need http://my.com/siterev1/postX to map to postX in the WordPress install, not sure if above specifically enables that. (I'm terrible at Apache rewrite stuff.) Also: not concerned about /fish/saltwater/shark.php getting redirected to /fish/index.php; maybe want /fish/saltwater/shark.php to get mapped to /fish/index.php=<something>?saltwater/shark (syntax not right, "reaching" for concept)? –  Johnny Utahh Feb 20 '12 at 16:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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