1

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
  • Check first, permissions of test directory, and test.php file. They should be 755, and 644, respectively. Change them, if they are not. That should fix the problem. If the problem does not go away, edit your question, and include a content of .htaccess file. – Frank P. Walentynowicz Nov 9 '17 at 17:46
  • Did you add the test directory in the document root (eg. public_html, htdocs, etc.)? – MrWhite Nov 9 '17 at 17:48
  • @MrWhite is in the directory with wp-admin, wp-content, wp-includes directories. Is it a problem? – Francesco Pegoraro Nov 9 '17 at 21:55
  • @FrankP.Walentynowicz I corrected test and test.php but it doesn't work. Editing the question as requested – Francesco Pegoraro Nov 9 '17 at 21:59
  • 1
    Those two RewriteCond lines in your htaccess check if it’s a physical file or directory first before handing off the request to WordPress, what you are describing is not default WordPress behavior. – Milo Nov 9 '17 at 22:39
2

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.

| improve this answer | |
0

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.

| improve this answer | |
  • 1
    I respectfully disagree. I do use many non-WordPress scripts, residing within WordPress structure, and none of my websites complains about it. – Frank P. Walentynowicz Nov 9 '17 at 22:24
  • Thank you, but I don't want to change the 404.php behaviour. I just want to create a custom route for my file so that when I type a specific url the custom code I created gets called and not the 404 of wordpress. – Francesco Pegoraro Nov 9 '17 at 22:25
  • @FrancescoPegoraro: WordPress, in its default settings, recognizes URLs ending with a file and its extension. I use them for a long time, to automate many tasks, and I run them from system cron, regularly. – Frank P. Walentynowicz Nov 9 '17 at 22:33
  • So how do I do it? – Francesco Pegoraro Nov 9 '17 at 22:43
  • @FrancescoPegoraro: read my last comment to your question. – Frank P. Walentynowicz Nov 9 '17 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.