将 URL 重写规则添加到 Wordpress [英] Add URL Rewrite Rule To Wordpress

查看:28
本文介绍了将 URL 重写规则添加到 Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Wordpress 插件,用于向 URL 添加查询字符串.但是我似乎无法修改 htaccess 来重写它.不确定 Wordpress 是否覆盖了它?

I've written a Wordpress plugin that adds a query string to the URL. However I can't seem to modify the htaccess to rewrite this. Not sure if Wordpress is overriding it?

当前的htaccess是:

The current htaccess is:

# 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

我要重写的 URL 是:

And the URL I'm trying to rewrite is:

http://domain.com/deal-info/?id=87&post_name=testdealtitle

所需网址:

http://domain.com/deal-info/87/testdealtitle

我尝试添加:

RewriteRule ^([^/]*)/([^/]*)$ /deal-info/?id=$1&post_name=$2 [L]

无济于事.任何想法表示赞赏!

to no avail. Any ideas appreciated!

推荐答案

经过多次困惑后,我在这里找到了答案:https://wordpress.stackexchange.com/questions/5413/need-help-带添加重写规则

After much confusion I found an answer here: https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule

虽然我认为正确的方法是:http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

Though I think the proper way to do it is by: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

我不确定您是否可以直接在 htaccess 中执行此操作,或者我与正在使用的另一个插件存在冲突问题.

I'm not sure if you can do this directly in htaccess, or I was having a conflict problem with another plugin I was using.

再次感谢 Olivier 的详尽回答!

Thanks again to Olivier for his extensive answer!

这篇关于将 URL 重写规则添加到 Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆