1

我在 WordPress 中使用 functions.php 创建了一些自定义菜单,我希望使用 htaccess 将这些 URL 重定向到友好的东西。例如,我为菜单设置的其中一个自定义菜单如下所示:http ://www.website.com/wp-admin/admin.php?page=for_buyers

我怎样才能将它重写为更像这样:

http://www.website.com/wp-admin/for-buyers/

此外,我的自定义子菜单如下所示:

http://www.website.com/wp-admin/admin.php?page=marketing_materials

我希望它更像这样:

http://www.website.com/wp-admin/for-buyers/marketing-materials/

4

1 回答 1

1

这个没测试过,最好是修改vhosts,不过可以使用perdir .htaccess:

在 /.htaccess 中,我们可以添加:

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^wp-admin/for-buyers/$ /wp-admin/admin.php?page=for_buyers [L]

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^wp-admin/for-buyers/marketing-materials/$ /wp-admin/admin.php?page=marketing_materials [L]

此规则集执行此操作:

  1. http://www.website.com/wp-admin/for-buyers/ => /wp-admin/admin.php?page=for_buyers
  2. http://www.website.com/wp-admin/for-buyers/marketing-materials/ => /wp-admin/admin.php?page=marketing_materials

或在 /wp-admin/.htaccess 中:

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^for-buyers/$ /wp-admin/admin.php?page=for_buyers [L]

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^for-buyers/marketing-materials/$ /wp-admin/admin.php?page=marketing_materials [L]
于 2013-11-09T23:25:53.190 回答