Solved

htaccess rewrite rule and pass variables

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 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

21 Experts available now in Live!

Get 1:1 Help Now