Solved

htaccess rewrite rule and pass variables

Posted on 2011-03-19
1
375 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now