admin管理员组文章数量:1122832
It seems that Wordpress has changed the default .htaccess
file so that you can no longer run different PHP code within the a subfolder. It also states that the block in the .htaccess
file is dynamically created, so messing with it directly would be problematic.
So what is the correct way to support running other PHP code that isn't related to Wordpress in a subfolder that Wordpress is installed?
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
It seems that Wordpress has changed the default .htaccess
file so that you can no longer run different PHP code within the a subfolder. It also states that the block in the .htaccess
file is dynamically created, so messing with it directly would be problematic.
So what is the correct way to support running other PHP code that isn't related to Wordpress in a subfolder that Wordpress is installed?
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Share
Improve this question
edited Jun 8, 2024 at 21:44
Exit
asked Jun 8, 2024 at 17:21
ExitExit
3194 silver badges12 bronze badges
4
|
1 Answer
Reset to default 0To run non-WordPress PHP files in a subfolder alongside a WordPress installation, follow these steps to modify your .htaccess
file:
Choose a Subfolder Name: Decide the name for your subfolder, e.g.,
mycustomphp
.Modify the .htaccess File: Add the following lines above the
# BEGIN WordPress
section to exclude your subfolder from WordPress's URL rewriting:RewriteEngine On RewriteRule ^mycustomphp/ - [L]
Ensure the entire .htaccess looks like this:
RewriteEngine On RewriteRule ^mycustomphp/ - [L] # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
This approach allows your PHP files to operate separately from the WordPress environment without altering core rewrite rules that could affect your main site.
本文标签: redirectRunning nonWordpress PHP files
版权声明:本文标题:redirect - Running non-Wordpress PHP files 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304275a1932178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.htaccess
file so that you can no longer run different PHP code within the same folder." At least for me, this doesn't seem to be the case. For example, I can have afoo.php
in the folder next to the.htaccess
and navigate to it via/foo.php
and it will run. – Wongjn Commented Jun 8, 2024 at 18:14foo.php
in some arbitrary subfolder and navigate to it via/some/arbitrary/folder/foo.php
and it will run. – Wongjn Commented Jun 8, 2024 at 21:54