如何在wordpress中使用.htaccess更改GET变量以获取漂亮的网址

时间:2017-07-18 09:09:05

标签: php wordpress apache .htaccess mod-rewrite

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

我有这个网址:

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

我想要这个

domain.com/parent-page/child-page-here/Some Text:

我更改了.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]

2 个答案:

答案 0 :(得分:0)

无需使用.htaccess,因为Wordpress附带了您需要的功能。您所要做的就是从管理信息中心将固定链接更改为here

答案 1 :(得分:0)

@mapmalith是正确的,使用WordPress,您只需更改设置中的永久链接即可。

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

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

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

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