Alireza Seyedzade
Alireza Seyedzade

Reputation: 346

rewrite wordpress plugin url somthing else

I'm developing a plugin for wordpress. I want to rewrite the plugin url.for example I have this :

http://www.domain.com/wp-content/plugins/myplugin/common/user/panel.php

which is a panel for wordpress users to do some thing. How can rewrite that url to this ?

http://www.domain.com/panel

Upvotes: 0

Views: 123

Answers (1)

Maai
Maai

Reputation: 369

Assuming you're purposely letting your users directly access your Wordpress plugin php file

You can do this by using .htaccess file and create a rewrite rule the way you have mentioned in your question.

The basic way to do it:

RewriteEngine On # Turn on the rewriting engine
RewriteRule ^/panel.php?$ /wp-content/plugins/myplugin/common/user/panel.php [L]

The first parameter is the matching url and the second one is the substitute url. Also [L] means this should be the last rule nothing should follow if matched.

Here's a good article if you're new to this: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

If not, simply catch the url request before Wordpress starts from your plugin

I would start with this:

add_action('parse_request', 'panel_handler_action');

function panel_handler_action() {
if($_SERVER["REQUEST_URI"] == '/panel.php') { //make sure /panel.php is not existing
      //do your stuff here
}
}

Upvotes: 1

Related Questions