• Resolved georgefarkas

    (@georgefarkas)


    I have some urls that point to pdfs in my uploads folder that need to rewrite to my uploads folder.

    My url is mydomain.com/subdir/pdfs/2/my_pdf_file.pdf

    I’d like it to rewrite to mydomain.com/subdir/wp-content/uploads/sites/2/my_pdf_file.pdf

    I’ve gotten this to work fine in a non-multisite install, but this code doesn’t work with multisite. Here’s my htaccess:

    # BEGIN PDF Rewrite
    RewriteEngine On
    RewriteBase /
    RewriteRule ^pdfs/([0-9]+)/([^/]+) /wp-content/uploads/sites/$1/$2
    # END PDF Rewrite
    
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    
    # END WordPress
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Why not just this?

    RewriteRule ^subdir/pdfs/.* /wp-content/uploads/sites/$1
    Thread Starter georgefarkas

    (@georgefarkas)

    That does simplify it, but it’s still not working. Any idea why this wouldn’t work as an htaccess rule? Did I mention that this is a Multisite?

    Alternatively, is there a way to use the rewrite API to link directly to a pdf file without it showing in the template?

    Thread Starter georgefarkas

    (@georgefarkas)

    It appears there’s something about Multisite rewrites that causes htaccess rules before the WordPress ones to be ignored. Is this the case? Or is there a special syntax required for this sort of (simple) rule to work?

    Thread Starter georgefarkas

    (@georgefarkas)

    Any suggestions, anyone? Maybe an alternate method to link to a pdf in my uploads folder with a prettier URL?

    Thread Starter georgefarkas

    (@georgefarkas)

    Okay, I figured it out. I wasn’t taking into account the subdirectory of the sub site. This is the code that works

    RewriteRule ^(.*)/pdfs/(.*)$ /$1/wp-content/uploads/sites/$2 [L]

    Thread Starter georgefarkas

    (@georgefarkas)

    Forgot to mark as resolved

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘RewriteRules in Multisite’ is closed to new replies.