Search code examples
wordpress.htaccessmod-rewriteurl-rewritingamember

Merging .htaccess Documents - Wordpress and aMember


How would one go about merging these two .htaccess files? I keep triggering 500 errors.

  • Each version works beautifully on its own.
  • Amember .htaccess (1st) protects access I believe should be implemented first.
  • Wordpress .htaccess (2nd) is needed for clean urls.

htaccess 1)

########### AMEMBER START #####################
Options +FollowSymLinks
RewriteEngine On

## allow access for product #12        
RewriteCond %{HTTP_COOKIE} amember_nr=([a-zA-Z0-9]+)
RewriteCond /home/www/changed.tld/amember/data/new_rewrite/%1-12 -f 
RewriteRule ^(.*)$ - [L]

## if user is not authorized, redirect to login page
# BrowserMatch "MSIE" force-no-vary
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^(.*)$ http://changed.tld/amember/plugins/protect/new_rewrite/login.php?v=-12&url=%{REQUEST_URI}?%{QUERY_STRING} [L,R]
RewriteRule ^(.*)$ http://changed.tld/amember/plugins/protect/new_rewrite/login.php?v=-12&url=%{REQUEST_URI} [L,R]
########### AMEMBER FINISH ####################

htaccess 2)

# BEGIN WordPress
<IfModule mod_rewrite.c>
#RewriteEngine On
RewriteBase /localsearch/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /localsearch/index.php [L]
</IfModule>
# END WordPress

AddType application/octet-stream .pdf

Solution

  • My thinking was backwards. Trick was to 'rewrite' the wp links first and then run the amember protect .htaccess next. Below is what ended up working for me. Specifically note the missing [L] in the last line of the WP rewrite.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /localsearch/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /localsearch/index.php 
    </IfModule>
    
    # END WordPress
    
    ########### AMEMBER START #####################
    Options +FollowSymLinks
    RewriteEngine On
    
    ## allow access for product #12        
    RewriteCond %{HTTP_COOKIE} amember_nr=([a-zA-Z0-9]+)
    RewriteCond /home/www/changed.tld/amember/data/new_rewrite/%1-12 -f 
    RewriteRule ^(.*)$ - [L]
    
    ## if user is not authorized, redirect to login page
    # BrowserMatch "MSIE" force-no-vary
    RewriteCond %{QUERY_STRING} (.+)
    RewriteRule ^(.*)$ http://changed.tld/amember/plugins/protect/new_rewrite/login.php?v=-12&url=%{REQUEST_URI}?%{QUERY_STRING} [L,R]
    RewriteRule ^(.*)$ http://changed.tld/amember/plugins/protect/new_rewrite/login.php?v=-12&url=%{REQUEST_URI} [L,R]
    ########### AMEMBER FINISH ####################