编辑的.htaccess与WordPress的插件API? [关闭]

问题描述 投票:4回答:1

我想写的是需要改变的.htaccess文件中的WordPress插件。我如何做到这一点在PHP。我已经看到了这与其他插件以前做过,但我无法弄清楚它是如何做。谢谢!

php wordpress wordpress-plugin
1个回答
9
投票

在WordPress的功能更新.htaccess文件insert_with_markers它有三个参数。

insert_with_markers ( string $filename, string $marker, array|string $insertion )

在以下这个tutorial你可以写这样的事情

// Get path to main .htaccess for WordPress
$htaccess = get_home_path().".htaccess";

$lines = array();
$lines[] = "RewriteBase /foobar";

insert_with_markers($htaccess, "MyPlugin", $lines);

这看起来像这样在您的.htaccess文件

# BEGIN MyPlugin
RewriteBase /foobar
# END MyPlugin

下面是WordPress的该函数的文档的链接

https://developer.wordpress.org/reference/functions/insert_with_markers/

© www.soinside.com 2019 - 2024. All rights reserved.