Custom URL on a single page in Wordpress

1.3k views Asked by At

I'm trying to figure out how to create a custom URL for only one page on Wordpress. The answer here might be pointing in the right direction but I'm not really sure how to implement it. How can I change the URL for a single page in Wordpress?

In wordpress I was hoping to create a page and let's say for example the default URL of that page is http://wordpress/?page_id=772
I want to change that URL to be the following

http://wordpress/share_this.php?pid=rk_379061

The URL must be in that format as the url is generated and embedded into an email by 3rd party software.

So I was thinking if there was a way to change page_id=772 to share_this.php and then allow the file some way to consume the parameters pid=rk_379061.

I've had a look at my .htacess file and it just includes the following : # BEGIN WordPress # END WordPress

I'm not really where else to look.

Any ideas. and thanks in advance

2

There are 2 answers

3
Jon Lin On BEST ANSWER

Do you mean something like this (must be above your # BEGIN WordPress line)

RewriteEngine On
RewriteRule ^share_this\.php$ /?page=772 [L,QSA]

This will take the request /share_this.php?pid=rk_379061 and rewrite it to: /?page_id=772&pid=rk_379061, so that the pid parameter can be accessed.

0
jeffjenx On

Add a share_this.php file to your Wordpress root that uses $_GET['pid'] and do whatever you need to do with it.

Example:

// wordpress/share_this.php

<?php

$pid = $_GET['pid'];
if( $pid == "rk_379061" )
{
    header( "Location: /?page_id=772" );
}
else
{
    header( "Location: /" );
}

?>