Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with Kumar's answer chosen by CommunityBot
grammar
Source Link

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore waswere not helpful in my case.

Thank you for any help.

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore was not helpful in my case.

Thank you for any help.

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore were not helpful in my case.

Thank you for any help.

Notice added Canonical answer required by Lorenz Meyer
Bounty Started worth 50 reputation by Lorenz Meyer
added 27 characters in body
Source Link

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore was not helpful in my case.

Thank you for any help.

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore was not helpful in my case.

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore was not helpful in my case.

Thank you for any help.

Source Link

Custom rewrite, url path with parameters to a page

I'm developing a plugin, that should display content according to two optional parameters in the URL. The following URL should all be treated by the plugin:

/pluginpage/
/pluginpage/value1/
/pluginpage/value1/value2/

Now I have put in place these things:

  • A page with a shortcode [myplugin] and the URL /pluginpage/
    • The shortcode that displays the content taking the parameters from the $_GET variable
    • The plugin works if the URL looks like /pluginpage/?param1=value1&param2=value2
  • Two rewrite rules in place, that match the three URL patterns to the page with the shortcode
add_rewrite_rule('^(pluginpage)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]', 'top');
add_rewrite_rule('^(pluginpage)/(.*)/(.*)/?', 'index.php?name=$matches[1]&param1=$matches[2]&param2=$matches[3]', 'top');

The rewrite rules work, but not as expected. When navigating to /pluginpage/value1/ or /pluginpage/value1/value2/ the page with the shortcode is displayed, but there is a redirect to /pluginpage/ and the parameters are lost during the redirect.

There is a missing piece that tells wordpress to not redirect from /pluginpage/value1/ to /pluginpage/. What exactly is missing?

Or might there be a better approach by mapping the URLs directly to the plugin without using a page and a shortcode?

This question is quite similar, but the answers are lacking important details, and therefore was not helpful in my case.