JamesConnor Posted August 10, 2013 Share Posted August 10, 2013 (edited) So I want my url to look like this... www.website.com/home&foo=bar&hello=world I only want the first get parameter to change the actual "behind the scenes" url is this... www.website.com/index.php?page=home&foo=bar&hello=world All tutorials I find change all of the parameters. Any help much appreciated! Edited August 10, 2013 by JamesConnor Quote Link to comment https://forums.phpfreaks.com/topic/281022-url-rewrite-get-parameters/ Share on other sites More sharing options...
jazzman1 Posted August 10, 2013 Share Posted August 10, 2013 (edited) Assuming we have next web structure: / (web root, probably it called public_html in environment websites dev setup ) / work_dir (your project folder) /work_dir/display.php (your display page) /work_dir/.htaccess ( your .htaccess file) The easiest way to do that, is to provide URLs to users as expected. In that case you want to be ( home&foo=bar&hello=world ) So, go to the display.php file and create your fake URLs: display.php <?php if (isset($_GET['page'])) echo '<pre>'. print_r($_GET, true).'</pre>'; ?> <a href="./home&foo=bar&hello=world">Query String 1</a><br /> <a href="./jazz_music&foo=jazz&hello=jazzman">Query String 2</a><br /> <a href="./rOcK&foo=rock&hello=rockman">Query String 2</a><br /> .htaccess RewriteEngine On RewriteBase /work_dir RewriteRule ^/?([a-zA-Z_]+)&foo=([a-zA-Z_]+)&hello=([a-zA_Z_]+)$ display.php?page=$1&foo=$2&hello=$3 [L] The regExp accepts in the case above - letters (capital and small) and underscors, you can expand it as you wish. Edited August 10, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/281022-url-rewrite-get-parameters/#findComment-1444322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.