John Lee
John Lee

Reputation: 55

URL Redirect Mod_rewrite with htaccess in WordPress

I have created some custom menus using functions.php in WordPress and I was hoping to use the htaccess to redirect those URLs to something friendly. For instance, one of the custom menus I have look like this for the menu: http://www.website.com/wp-admin/admin.php?page=for_buyers

How can I re-write it to be more like this:

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

Also, My custom sub-menu look like this:

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

I want it to be more like this:

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

Upvotes: 1

Views: 228

Answers (1)

jacouh
jacouh

Reputation: 8741

This has not been tested, the best is to modify vhosts, but you can use perdir .htaccess:

in /.htaccess, we can add this:

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]

This ruleset does this:

  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

Or in /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]

Upvotes: 1

Related Questions