Skip to content

Instantly share code, notes, and snippets.

@andymagill
Last active December 11, 2022 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymagill/e56f411a1124f6cf74f87cb0b3252995 to your computer and use it in GitHub Desktop.
Save andymagill/e56f411a1124f6cf74f87cb0b3252995 to your computer and use it in GitHub Desktop.
HTACCESS rewrite rule not working on SiteGround
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# don't rewrite anything in docs folder to wordpress
RewriteCond %{REQUEST_URI} !^/(docs/*) [NC]
RewriteRule . /index.php [L]
# rewrite docs
RewriteRule ^/docs/Resume-Andrew-Magill.pdf$ "/wp-content/uploads/2019/11/Resume-Andrew-Magill-191112.pdf" [L]
RewriteRule ^/docs/Cover-Letter-Andrew-Magill-Dropbox.pdf$ "/wp-content/uploads/2019/11/Cover-Letter-Andrew-Magill-Dropbox-191121.pdf" [L]
</IfModule>
@augusthostdev
Copy link

augusthostdev commented Dec 11, 2022

Did you get a solution with this ? I'm having the same issue.

I tested it at my localhost with Apache and it works but not on Siteground.

My .htaccess is

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# Protect .pdf file direct access
RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ pdf-auth.php?file=$1 [QSA,L]
</IfModule>

# END WordPress

@augusthostdev
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment