Jump to content

URL Rewrite GET parameters


JamesConnor

Recommended Posts

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 by JamesConnor
Link to comment
Share on other sites

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 by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.