HOW TO Solve 403 Forbidden Issue WordPress permalink clash folder name

For some years ago, I’ve used WordPress as sub-folder to prevent hackers can find the real folder of blog softwares. Now, I’m hosting WordPress at root director of domain but I still keep old folder that called as wordpress to keep live urls of media, photos, files, demo… I don’t expect it had 403 Forbidden Issue when user visit WordPress category because WordPress permalink clashed with director name: wordpress. It’s been the way it is for a long time now and I never thought there was a problem until one kind person contact me then told me what did happened. I decided to run everything through WordPress by doing a clean install at the web root after changed web hosting service.

Fix 403 Forbidden Issue WordPress permalink clash folder name
Fix 403 Forbidden Issue WordPress permalink clash folder name

The reason that’s happening at all is because of content negotiation. Since there is an actual matching directory, your server will not reach WordPress to process the URI if it encounters a directory first. You will need to either rename your directory or change the permalink for the page in order to have both working.
I disabled directory browsing in the .htaccess file and there’s no index.php, a request for /wordpress/ should return a 403 Forbidden response code. If I enable directory browsing, the page doesn’t render and I get the standard Apache directory view.
After I spent 1 hour to research with Google, I found that it is not necessary to rename the conflicting directories. One thing to do just you need to create an exception for each page that you want WordPress to handle.
Default WordPress Permalink structure

# BEGIN WordPress

	RewriteBase /
	RewriteRule ^index\.php$ - [L]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /index.php [L]

# END WordPress

These rules basically tell the server to pass any requests ending in directories with those names to /index.php which is WordPress’ main script. In order to prevent matching any URL ending in /wordpress/ etc. It is necessary to qualify the conditions with enough of the path names to those directories on your server to make them unique.

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Fix 403 errors on existing directories; WordPress overrides.
RewriteCond %{REQUEST_URI} ^/(wordpress)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

# END WordPress

The server path must be used here because I am matching against %{REQUEST_FILENAME}. I suppose %{REQUEST_URI} would allow you match against the URL instead but I haven’t tried it.
If you had more than one director which clashed with WordPress Permalink, just add:

# BEGIN WordPress

....
# Fix 403 errors on existing directories; WordPress overrides.
RewriteCond %{REQUEST_URI} ^/(wordpress|folder1|folder2)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

# END WordPress

Notes: WordPress will replace this code snippet if you update the permalink structure.

1 thought on “HOW TO Solve 403 Forbidden Issue WordPress permalink clash folder name”

Comments are closed.