Skip to main content

Accessing local directory content from wordpress

Sometimes you want to upload some files into a local directory in your wordpress installation directory and link these files in your posts. To achieve this you have to modify your .htaccess file in your wordpress installation directory and put this directives before WordPress directives. Assuming you want to store some files in “files” directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/files/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>

The final file content looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/files/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>

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

# END WordPress

Now, you can link this files in your posts with www.yourdomain.com/files/myfile.txt

One thought to “Accessing local directory content from wordpress”

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.