Solved

htaccess rewrite rule and pass variables

Posted on 2011-03-19
1
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

624 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