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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.