简体   繁体   English

如何让我的wordpress插件向.htaccess添加重写规则?

[英]How do I get my wordpress plugin to add rewrite rules to the .htaccess?

I have been working with WP for years but this is my first time working on a plugin that needs new rewrite rules. 我已经和WP合作多年了,但这是我第一次使用需要新重写规则的插件。

I have a single rule I need to add to the .htaccess file 我有一个规则需要添加到.htaccess文件中

RewriteRule ^loan-application/step([0-9])|(stepsuccess)/?$ index.php?pagename=loan-application&step=$1 [NC,L]

How do I make the plugin add this to the file? 如何使插件将其添加到文件中?

Thanks in advance. 提前致谢。

To open and add that: 要打开并添加:

$file = fopen(".htacces",a+);
fwrite( $file, "RewriteRule ^loan-application/step([0-9])|(stepsuccess)/?$ index.php?pagename=loan-application&step=$1 [NC,L]");

Only take care where is the file having this function, and where is .htaccess. 只关注具有此功能的文件在哪里,以及.htaccess在哪里。

fopen - http://php.net/manual/en/function.fopen.php fwrite - http://php.net/manual/en/function.fwrite.php fopen - http://php.net/manual/en/function.fopen.php fwrite - http://php.net/manual/en/function.fwrite.php

I don't believe you should be modifying .htaccess directly. 我不相信你应该直接修改.htaccess。 There's a WordPress class to manage rewrite rules which has the ability to overwrite all or part of the WordPress .htaccess (likely overwriting any changes you have made): 有一个WordPress类来管理重写规则,它能够覆盖全部或部分WordPress .htaccess(可能会覆盖你所做的任何更改):

http://codex.wordpress.org/Rewrite_API http://codex.wordpress.org/Rewrite_API

Indeed, I believe you should actually be using this class to achieve your goal. 实际上,我相信你应该真正使用这个课程来实现你的目标。 Unfortunately, I stumbled on this question while researching these rules for the first time so I'm not (yet) able to provide any further detail. 不幸的是,我在第一次研究这些规则时偶然发现了这个问题,所以我(还)无法提供任何进一步的细节。 The best guide I've found (so far) is: 我发现(目前为止)最好的指南是:

http://www.hongkiat.com/blog/wordpress-url-rewrite/ http://www.hongkiat.com/blog/wordpress-url-rewrite/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM