简体   繁体   English

Wordpress中的自定义.htaccess重写规则未执行

[英]Custom .htaccess rewrite rules in wordpress not executing

Issue: 问题:

I'd like to be able to modify a url query string parameter for a plugin in wordpress, and take the original url; 我希望能够为wordpress中的插件修改url查询字符串参数,并采用原始url;

/wp-admin/admin.php?page=espresso_events /wp-admin/admin.php?page=espresso_events

and be able to access it via; 并能够通过以下方式访问它:

/wp-admin/admin.php?page=events /wp-admin/admin.php?page=events

As far as I can tell everything in my .htaccess file is correct, but for some reason it still doesn't work. 据我所知,我的.htaccess文件中的所有内容都是正确的,但由于某种原因,它仍然无法正常工作。 The rules however look fine, so I cannot understand why wordpress is throwing me an error when I try to access the page via the new url. 但是规则看起来不错,所以当我尝试通过新的url访问页面时,我无法理解wordpress为什么向我抛出错误。

This is my .htaccess file; 这是我的.htaccess文件;

RewriteEngine On
RewriteBase /event_espresso/
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)events(.*)$
RewriteRule . wp-admin/admin.php?%1espresso_events%2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /event_espresso/index.php [L]

Using this online tool, it gives me the correct output url, but when I try the input url directly in wordpress, I just get the same error each time; 使用在线工具,它可以为我提供正确的输出网址,但是当我直接在wordpress中尝试输入网址时,每次都会得到相同的错误;

You do not have sufficient permissions to access this page. 您没有足够的权限访问此页面。

Edit: 编辑:

This is definitely a wordpress issue. 这绝对是一个WordPress的问题。 When I manually update my .htaccess file, everything works correctly, however, when using the mod_rewrite_rules filter, wordpress doesn't appear to be writing the rule to my .htaccess file, or executing them. 当我手动更新.htaccess文件时,一切正常,但是,当使用mod_rewrite_rules过滤器时,wordpress似乎没有将规则写入我的.htaccess文件或执行它们。 I have full write permissions on my .htaccess file. 我对.htaccess文件具有完全写入权限。

This issue has been resolved now. 该问题现已解决。 I wasn't flushing the rewrite rules properly via my plugin, so my rewrite rules weren't even being added to the .htaccess file. 我没有通过插件正确刷新重写规则,因此甚至没有将重写规则添加到.htaccess文件中。

function plugin_activate()
{
    //make sure rewrite rules are flushed so the htaccess is written to
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

register_activation_hook(__FILE__, 'plugin_activate');
//actions..

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

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