.htaccess with SilverStripe and WordPress

Ok, basically I need to be able to set my .htaccess so that it works for SilverStripe install in root directory and blogs installed in the /blogs directory. Here is what I have:

### SILVERSTRIPE START ###
<Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Files>

<Files web.config>
    Order deny,allow
    Deny from all
</Files>

ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html

<IfModule mod_alias.c>
    RedirectMatch 403 /silverstripe-cache(/|$)
</IfModule>

<IfModule mod_rewrite.c>
    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine On

    # BEGIN Silverstripe
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
    # END Silverstripe

    # BEGIN WordPress
    RewriteBase /blogs/aquiman/
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blogs/aquiman/index.php [L]

    RewriteBase /blogs/aquipad/
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blogs/aquipad/index.php [L]
    # END WordPress

</IfModule>
### SILVERSTRIPE END ###

This of course does not work. And I know it is wrong, but I don’t know enough to fix it. Please help me correct this to make it work right.

Read More

Thanks,
JH

Related posts

Leave a Reply

1 comment

  1. One simple advise keep it separate i.e.

    • Keep SilverStripe related code in $DOCUMENT_ROOT/.htaccess with RewriteBase /
    • Keep WordPress related code in $DOCUMENT_ROOT/blog/.htaccess with RewriteBase /blog/

    Here is a modified Rewrite code you should use in $DOCUMENT_ROOT/.htaccess:

    # BEGIN Silverstripe
        RewriteBase /
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l
        RewriteRule (?!^blog/)^.*$ sapphire/main.php?url=$1 [L,QSA,NC]
    # END Silverstripe