How do I skip wordpress’s 404 handling?

I want to extend my website in a way that is parallel to the wordpress theme.

Example:

My website with wordpress is at: www.mywebsite.com
By ftp I added a directory named test, in which there is a php file test.php

The problem is that if I write in the url: www.mywebsite.com/test/test.php it redirects me to the “page not found” of my theme.

How can I deactivate this behavior?

Posting .htaccess:

# 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

# # av:php5-engine
AddHandler av-php5 .php

# # av:Toolbar
SetEnv AV_TOOLBAR 1

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Native WordPress rules are designed to ignore any existing files and directories, including arbitrary PHP scripts. This is literally what this part of directives mean:

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

So under normal circumstances WP just shouldn’t be involved with your request in any way. You may have some other rewrite rules interfering, possibly from a different place in web server configuration.

Method 2

IIRC, you cannot execute ‘plain’ (non-WP-code) PHP code on a WordPress site. WP will use the URL as a ‘pointer’ to an entry (page/post) in your WP database. It will not load/run the PHP code in the file.

If you want to have a customized 404 file, then create a child theme and then copy/modify the 404.php file from the parent theme. Lots of googles on how to create child themes (and why they are important).

There are plugins that will allow you to put PHP code in a page/post. But, based on your question, the best solution is a customized 404 template.

** Edit **
I stand corrected. A non-WP PHP page can be displayed on a WP-based site. Of course, it doesn’t have any of the site’s “look” (for which you’d want to use a template with your PHP code), but it does work.

I always thought that it wouldn’t, based on some murkily-remembered past experience.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x