【问题标题】:How to rewrite URL in wordpress如何在wordpress中重写URL
【发布时间】:2014-05-02 18:35:32
【问题描述】:

我在为 wordpress 重写 url 时遇到一些问题

我有这样的网址:

http://example.com/mentor-profile/?mentor_slug=dr-jonathan-fass
http://example.com/mentor-profile/?mentor_slug=neha

这对用户和 SEO 不友好,我想要这样的 URL:

http://example.com/dr-jonathan-fass
http://example.com/neha

我正在更改.htaccess 文件,但出了点问题。谢谢。

【问题讨论】:

标签: wordpress .htaccess url-rewriting


【解决方案1】:

基本上,Wordpress 允许您使用 SEO 和用户友好的 URL,只需更改 Administration area -> Settings -> Permalinks 中的 permalink 设置并将它们设置为 Post name

更多信息 - here

【讨论】:

  • 是允许但不适用于我的插件,因为我没有为我自己的插件使用自定义帖子类型来添加导师
【解决方案2】:

您可以使用 wordpress 插件来编辑 url,如下所示:

http://wordpress.org/plugins/custom-post-type-permalinks/

或在同一网站上搜索适合您要求的另一个

【讨论】:

  • 不,我正在使用我自己的插件来添加导师,因此自定义帖子类型插件将与我自己的插件不兼容。我想通过 htaccess 来做到这一点
【解决方案3】:

所需的重定向可以像这样工作:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&?mentor_slug=([^&]+)&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /%2? [R=302,L]

无论如何,您还应该定义其他情况,例如:

参数之前是否有文件夹?例如在以下情况下应该发生什么:
http://example.com/mentor-profile/test/asd/albala/?mentor_slug=dr-jonathan-fass
这些文件夹应该保留还是删掉?

如果有其他参数应该怎么办,例如:
http://example.com/mentor-profile/?test=asd&ala=balab&mentor_slug=dr-jonathan-fass&hi=hello
其他参数应该保留还是丢失?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-04
    • 2016-03-04
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    相关资源
    最近更新 更多