WordPress: remove the URL rewrite rule directory for .htaccess

How to directly access a directory in the root of the server hosting if WordPress is configured to work as a friendly URL?

htaccess

Problem

We all know that when you want to access a directory in the root of the server, simply put the domain followed by the name of that directory. So, for example, If the directory is called “uploads”, you access it by address http://taylorlopes.com/uploads.

The problem is that when setting up WordPress (or any other system) with friendly URL, What was once a page called contacts with a URL http://taylorlopes.com/?page_id = 2, becomes something like http://taylorlopes.com/contatos. Note that this new way of getting the URL (DITA friendly), It resembles the call of an directory, being that contacts actually it's not a directory, but just one page.

Soon, from the moment you decide to use friendly URL is impossible to draw a directory, because WordPress interprets this as a call to a page, that obviously does not exist, and throws the error “OPS! This page cannot be found“. So, How to draw a directory without the WordPress interpret this call as being to a page?

Solution

To resolve this issue and be able to directly access a directory in the root of the server without the WordPress interpret it as a page, open the .htaccess and add the following line right below the first statement RewriteRule, changing “MyDir” the name of your current directory:

Partial code

RewriteCond %{REQUEST_URI} !^/(MyDir|MyDir/.*)$

Complete code

# BEGIN WordPress
<IfModule mod_rewrite.c>
Rewriteengine On RewriteBase /
RewriteRule ^ index .PHP $ - [L]
RewriteCond %{REQUEST_URI} !^/(MyDir|MyDir/.*)$
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L]
</IfModule>
# END WordPress

Note:

The .htaccess is at the root of the directory where the Web content is published, as for example in the directory /www (WampServer) or in the /htdocs (XAMPP).

Redirect

The idea here is to make a Post (page) answer by two friendly URL, in this way, When someone type http://taylorlopes.com/about (the page about does not exist) be made a redirect to http://taylorlopes.com/sobre (page about There is). Use the .htaccess to do the redirection:

Partial code

Redirect /about /about

Complete code

# BEGIN WordPress
<IfModule mod_rewrite.c>
Rewriteengine On RewriteBase /
RewriteRule ^ index .PHP $ - [L]
RewriteCond %{REQUEST_URI} !^/(util|util/.*)$
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-(d) Redirect /about /about RewriteRule . /index.PHP [L]
</IfModule>
# END WordPress

Source

WordPress: Exclude directory from rewrite URL with .htaccess

Total hits: 7833

Leave a reply

The your email address will not be published. Required fields are marked with *