如何在htaccess中重写Wordpress url

时间:2014-08-13 16:21:47

标签: php wordpress apache .htaccess url-rewriting

我是Wordpress的新手。我现在遇到了关于url重写规则的问题。

我在" homepage.php"中创建了一个搜索表单。和这种形式的三个领域。如果用户提交此表单,则会将三个参数发送到另一个Wordpress页面"结果"(slug:results)。

<form class="filter-form" action="<?php echo get_permalink( get_page_by_title( 'Results' ) ); ?>" method="get" role="form">

我创建一个名为&#34的页面;结果&#34;使用&#34; results.php&#34;作为自定义页面模板。

这三个变量是:1.degree(string)2.postcodecity(string)3.department(number eg:75)

但这三个变量并不总是有价值的。以下是5种情况:

1.degree 2.postcodecity 3.department 4.degree&amp; postcodecity 5.degree&amp;系

我现在有这样的网址:

www.example.com/results/?degree=college&postcodecity=&department =

我需要将此网址重写为友好版本:

1.www.example.com/results/college(degree)

2.www.example.com/results/75003 - 巴黎(邮政编码)

3.www.example.com/results/75(部门)

4.www.example.com/results/college/75003 - 巴黎(学位与邮政编码)

5.www.example.com/results/college/75(学位与部门)

注意:我想直接在[.htaccess]文件中执行此操作。

有人可以帮助我吗?非常感谢。

1 个答案:

答案 0 :(得分:0)

最后,我放弃了改变.htaccess文件的方法,并引用了Wordpress方法。 php中的编码更容易控制。

要实现我的目标,应该采取以下两个步骤:

1.使用wp_redirect(Wordpress函数)生成漂亮的URL格式。

2.使用add_rewrite_rule(Wordpress函数)添加自定义重写规则,以告诉Wordpress如何解释您的漂亮URL。

相关问题