Question: How do you tell Wordpress to ignore a folder, in favor of a permalink?


How do you tell Wordpress to ignore a folder, in favor of a permalink?

Answers 1
Added at 2017-01-04 18:01

I have a client who had a non-WordPress site, with a WordPress blog located in a subfolder /blog/. We launched them a new WordPress site in the root. Unfortunately, all the images in their blog posts are still pointing at /blog/wp-content/uploads/. I want to just add all these images to a subfolder on the file tree at /blog/wp-content/uploads, so it will just automagically fix all those broken images without extra work from me.

The problem is that their new blog page is located at /blog/. I can't change this for SEO reasons. If I move the images, then navigating to /blog/ doesn't show the WordPress page, it shows a folder on the file tree.

I want it to show the WordPress page instead. Is there a way to tell WordPress to ignore that folder, and show the WordPress page when /blog/ is called instead?

nr: #1 dodano: 2017-01-04 19:01

The WordPress front controller only routes the request when you don't request a physical file or directory on the file system. The problem here is that when you create a physical directory called /blog then WP will no longer route the request and you see the directory.

Aside: You shouldn't really be seeing the directory contents, ideally you should get a 403 Forbidden. Add Options -Indexes to the top of your .htaccess file.

The default WP .htaccess contains the following lines that excludes physical files and directories from being routed (ie. so that static resources can be accessed).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

You can make an exception for the /blog subdirectory by changing this to:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/blog/?$
Source Show
◀ Wstecz