【问题标题】:How to change GET variables using .htaccess in wordpress for pretty URL如何在 wordpress 中使用 .htaccess 更改 GET 变量以获得漂亮的 URL
【发布时间】:2017-07-18 20:05:40
【问题描述】:

我知道如何更改PHP 中的 URL,但我不是 WordPress 专家。

我有这个网址:

domain.com/parent-page/child-page-here/?id=SomeText

我想要这个

domain.com/parent-page/child-page-here/一些文字:

我更改了.htaccess,但它在这里不起作用是我的.htaccess 代码

# 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
RewriteEngine On
RewriteRule ^parent-page/child-page/([0-9a-zA-Z]+) parent-page/child-page/?id=$1 [NC,L]

【问题讨论】:

    标签: php wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    无需使用 .htaccess,因为 Wordpress 带有您需要的功能。您所要做的就是从管理仪表板将永久链接更改为here

    【讨论】:

    • 我正在使用来自 parmalink 的帖子名称。我在 id="text" 中发送数据并从自定义页面 $_GET[''id"] 获取数据并将此值发送到数据库以获取结果
    • 能否请您告诉如何从 .htaccess 文件更改 URL 并立即执行此操作 RewriteRule ^parent-page/child-page/([a-zA-Z0-9-]+)/? $ parent-page/child-page/index.php/?id=$1 [L] 但它不起作用
    【解决方案2】:

    @mapmalith 是正确的,使用 WordPress,您可以简单地更改设置中的永久链接。

    但是,如果由于某种原因您无法执行此操作,则可以在 .htaccess 文件中使用以下内容:

    RewriteEngine On
    RewriteRule ^parent-page/child-page-here/([^/]*)$ /parent-page/child-page-here/?id=$1 [L]
    

    它将为您提供以下 URL:domain.com/parent-page/child-page-here/SomeText。请确保在测试之前清除缓存。

    显然您需要将目录重命名为正确的名称。

    【讨论】:

    • 我已经选择了 post-name 表单仪表板,我只是试过你的代码它不起作用它给我内部服务器错误
    • 这是我的 .htaccess 文件(# BEGIN WordPress RewriteEngine On RewriteRule ^aircraft-gallery/aircraft-gallery-class/([^/]*)$ aircraft-gallery/ aircraft-gallery-class/?id=$1 [L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L ] #END WordPress)
    • 你在吗..?
    猜你喜欢
    • 2013-02-16
    • 1970-01-01
    • 2013-02-13
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 2021-07-01
    • 1970-01-01
    相关资源
    最近更新 更多