.htaccess - how to tell wordpress to ignore a directory
My wordpress website has seo friendly urls like http://mysite.com/mywebpage
. I installed wordpress in my /var/www
directory.
However, on my server, I also have a directory called /var/www/mywebpage
because that directory holds files like /var/www/mywebpage/product1.jpg
, /var/www/mywebpage/product2.jpg
etc...
Now everytime I go to http://mysite.com/mywebpage
, the browser gives me a 403 Forbidden error because if a directory with the same name as a wordpress page exists, then the directory takes precedence. I have a few more web directories that suffer from this problem.
How do i edit my .htaccess file such that a wordpress page takes precedence over the following three directories: /var/www/mywebpage
, /var/www/myproductpage
and /var/www/mygraphics
.
However, if someone goes to http://mysite.com/mywebpage/product1.jpg
, i want them to be able to see the physical image file.
Here's my current .htaccess from Wordpress.
# WORDPRESS Rules below, DO NOT EDIT!
#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
The simplest answer (and more maintainable in the long run, without getting into more mod_rewrite
or mod_alias
black magic) is really to not name the directories the same as your seo-friendly-links. Use something like mywebpage_images
, myproductpage_images
, etc. for these directories.