How to convert get strings to slug?
<p><strong>Bounty Note: I've found my solution for my question using add_rewrite_rules. I will reward the bounty to anyone who can provide me with the same solution in apache RewriteRules format.</strong></p>

<p>I've read <a href="https://stackoverflow.com/questions/3033407/how-can-i-create-friendly-urls-with-htaccess">How can I create friendly URLs with .htaccess?</a> but it still difficult and complicate to me.</p>

<p>I am running WordPress Multisite, and I have a sub domain website cp.example.com and I'm writing a php app on this sub domain.</p>

<p>I have a website address that is looks like this: </p>

<pre><code>http://cp.example.com/sales.php?id=12345&amp;userid=123456&amp;uid=83hkuhdqhuhd873xsuhdqwiuhdiq
</code></pre>

<p>Is it possible for me to let user access the website via:</p>

<pre><code>http://cp.example.com/sales/12345/userid/123456/83hkuhdqhuhd873xsuhdqwiuhdiq
</code></pre>

<p>And if I were to do that will php still be able to do <code>$_GET</code> on the values?</p>

<p>e.g <code>$_GET['id']</code>, <code>$_GET['userid']</code> and <code>$_GET['uid']</code>?</p>

<p>I'm using WordPress for my base, but i'm writing the app end, using a different table.</p>

<p>I'm trying to avoid using custom post type just to achieve the above.</p>

<p>I've tried the following.</p>

<ol>
<li><p>Create a template file view_sales.php in view_sales.php I will require <code>$_GET['id']</code>, <code>$_GET['userid']</code> and <code>$_GET['uid']</code> in order to retrieve info from mysql.</p></li>
<li><p>in <code>view_sales.php</code> I've also used a different header file and have <code>get_header('sales')</code>;</p></li>
<li><p>in header-sales.php I've added the following code gotten from the above stack overflow page.</p>

<pre><code>$path_components = explode('/', $_GET['url']);
$id=$path_components[0];
$userid=$path_components[1];
$uid=$path_components[2];
</code></pre></li>
<li><p>I created a new wp page with slug sales so now the website is 
<a href="http://cp.example.com/sales/?id=123456&amp;userid=123456&amp;token=98917397219372iheu1i" rel="nofollow noreferrer">http://cp.example.com/sales/?id=123456&amp;userid=123456&amp;token=98917397219372iheu1i</a></p></li>
<li><p>I only have one <code>.htacess</code> website in my <code>/public_html/example.com</code> domain since it's a multisite so I added the code suggested above to my <code>.htaccess</code> and now it looks like this.</p>

<pre><code>RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

&lt;IfModule mod_rewrite.c&gt;
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
&lt;/IfModule&gt;  
</code></pre></li>
</ol>

<p>Nothing is working at the moment, still redirecting to the ugly url. </p>

<p><strong>Edited:</strong></p>

<p>I've tried the following</p>

<pre><code>RewriteCond %{HTTP_HOST} !^cp\.example\.com [NC]
RewriteRule ^listing/([a-z0-9]+)$ listing/?action=$1 [L,NC] 
RewriteRule ^view/([a-z9-9]+)$ view/?id=$ [L,NC]
</code></pre>

<p>I tried different variants of all the above but nothing works.</p>

<p><strong>Edited for add_rewrite_rule method which i tried</strong></p>

<pre><code>function pa_custom_rules() {
    add_rewrite_rule('^/listing/([^/]+)/$', 'index.php?pagename=listing&amp;action=$matches[1]', 'top');
}
add_action('init', 'pa_custom_rules');
</code></pre>

<p>Printed the rewrite array and I can see the new rule</p>

<pre><code>      [^/listing/([^/]+)/$] =&gt; index.php?pagename=listing&amp;action=$matches[1]
</code></pre>

<p>Visiting index.php works but going to /listing/test/ fails. It returns 404 error.</p>