Solved

htaccess rewrite rule and pass variables

Posted on 2011-03-19
1
379 Views
Last Modified: 2012-06-21
Hi - My original page without rewrite was trying to pass 4 variables. I only want 2 of the four to be used within the rewrite (state and area) and still pass the two that I can $_REQUEST on the page. I got my original 2 working with a rewrite but I still cannot figure out the two passed variables. Once I added the content for variables, I'm getting page not found so obviously written wrong. Is my syntax wrong on the requests? Thanks in advance for any help.

Some data for troubleshooting.

RewriteRule ^([A-Z][A-Z])/(.*)/directory.php?type=(.*)&sortby=([A-Za-z]+)$ /company.php?area=$2&state=$1&type=$3&sortby=$4 [L]
 I would like my final rewrite to look like this.

/IL/Chicago/directory.php?type=all&sortby=gcs
And request variables on the page for: type (variables options are all, 1-4) and sortby (gcs or cn)
0
Comment
Question by:TLC1
1 Comment
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 125 total points
ID: 35175377
Your rewrite url should be like this:

RewriteRule ^([A-Z][A-Z])/(.*)/directory\.php company.php?area=$2&state=$1&%{QUERY_STRING} [L]

Open in new window


Requesting the url like:
/IL/Chicago/directory.php?type=all&sortby=gcs
will populate the $_GET array with the results below:

Array
(
    [area] => Chicago
    [state] => IL
    [type] => all
    [sortby] => gcs
)

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question