htaccess - Cannot Override Wordpress 404 for a Sub-Directory

admin2025-01-07  3

I have wordpress installed on my root (/var/www/html) and I have a sub-directory in the root as /var/www/html/manage Both directories have it's own .htaccess files. Content of the .htaccess are as follows.

/var/www/html/.htaccess (root)

# 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

/var/www/html/manage/.htaccess (Sub-directory)

# Start Manage .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 /lost.php

# End Manage .htaccess

I can rewrite .php extension of the the php files in the sub-directory with the .htaccess but I cannot use custom 404 as defined in the htaccess file in the sub-directory. When I go to www.example/manage/laksjdflskjf it shows wordpress 404 instead of lost.php

How Can I make the sub-directory to show its 404 instead of wordpress 404?

I have wordpress installed on my root (/var/www/html) and I have a sub-directory in the root as /var/www/html/manage Both directories have it's own .htaccess files. Content of the .htaccess are as follows.

/var/www/html/.htaccess (root)

# 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

/var/www/html/manage/.htaccess (Sub-directory)

# Start Manage .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 /lost.php

# End Manage .htaccess

I can rewrite .php extension of the the php files in the sub-directory with the .htaccess but I cannot use custom 404 as defined in the htaccess file in the sub-directory. When I go to www.example.com/manage/laksjdflskjf it shows wordpress 404 instead of lost.php

How Can I make the sub-directory to show its 404 instead of wordpress 404?

Share Improve this question asked Sep 5, 2015 at 3:40 Shamal SandeepShamal Sandeep 12 bronze badges 2
  • I'd guess that you have to put your rules to handle the manage subdirectory in root above the WordPress rules so they get parsed first. – Milo Commented Sep 5, 2015 at 4:10
  • Can you tell me how to do that? – Shamal Sandeep Commented Sep 5, 2015 at 7:21
Add a comment  | 

2 Answers 2

Reset to default 0

The way the wordpress htaccess works is that first it looks if there is a file matching the request location, in which case it is being "run", otherwise the wordpress handles the URl. Basically you don't even "execute" your subdirectory's htaccess unless you access an existing fie there.

What you should do is to add to the wordpress htaccess rules that will prevent it from handling urls under the subdirectory.

WordPress has its own 404.php file in theme.

WordPress will automatically use that page if a Page Not Found error occurs

You need to edit this file or if your theme don't have this file then you need to create it.

For more detail go to this link

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261237a725.html

最新回复(0)