SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member c0dingL!fe's Avatar
    Join Date
    Sep 2013
    Location
    Essex
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dealing with multiple $_GET variables with mod_rewrite

    Good afternoon all,

    I am having a problem with passing 2 values through my URL and I think it's something to do with my .htaccess file.

    When any internal link on my site is clicked, I pass a $_GET variable and depending on that value, display the relative page.

    I have an 'Offers' page containing 3 offers. There is a link for each offer and the idea is to populate my textarea on my contact page with the value of the offer, should they be linked to my contact page via the Offers page.

    Trouble is, my .htaccess file I believe only deals with the instance of 1 $_GET value being passed, but anymore and it doesn't work.

    My is here:
    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^/?([a-zA-Z_]+)$ index.php?page=$1 [L]
    How can I accommodate multiple values being passed?

    The website link is here: http://www.tspv-websites.co.uk/Offer

    Kind regards,

    c0dingL!fe

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,155
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    You'll need the query string append flag. "Appends any query string from the original request URL to any query string created in the rewrite target."

    RewriteRule ^/?([a-zA-Z_]+)$ index.php?page=$1 [L,QSA]
    "First make it work. Then make it better."

  3. #3
    SitePoint Member c0dingL!fe's Avatar
    Join Date
    Sep 2013
    Location
    Essex
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good evening,

    Thanks for the reply.

    I've added your code and it doesn't work for me.

    How should I write the second value?

    At the minute, this works for one variable:
    Code:
    <a href="./Contact">Contact</a>
    And i'm trying to pass the second like:
    Code:
    <a href="./Contact/Deal1">Deal 1</a>
    Kind regards,

    c0dingL!fe

  4. #4
    SitePoint Member c0dingL!fe's Avatar
    Join Date
    Sep 2013
    Location
    Essex
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good evening,

    Update:

    I've nearly got it working and the page loads, but for some reason the stylesheet is not being applied. Although when I look through developer tools, it is loaded in the <head>. No elements have any style whatsoever.

    If you visit here: http://www.tspv-websites.co.uk/Offer and click on the Deal 1 button, you will see exactly what I mean.

    Here is my code:
    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^/?([a-zA-Z_]+)$ index.php?page=$1 [L,QSA]
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_0-9]+)$ index.php?page=$1&deal=$2 [L]
    The URL looks good, the stylesheet is showing as loaded. This is very strange.

    Anyone got any thoughts?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    cL,

    The problem you're having is simply the change of directory level of the incoming request. When you redirect with multiple "entry" request directory levels, you either need the <base> tag or absolute URIs for your support pages. More in my signature's tutorial.

    As an aside, I'd recommend that you determine the Apache version you're using to get rid of the optional /'s and your RewriteBase / is doing nothing (useful) do I'd think that should be deleted, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,155
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c0dingL!fe View Post
    I've nearly got it working and the page loads, but for some reason the stylesheet is not being applied.
    You're rewriting most every URL to index.php, which means your CSS request is likely being rewritten as well. The simplest fix would be to exclude any real file from being rewritten.

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_0-9]+)$ index.php?page=$1&deal=$2 [L]
    "First make it work. Then make it better."

  7. #7
    SitePoint Member c0dingL!fe's Avatar
    Join Date
    Sep 2013
    Location
    Essex
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good morning both,

    I used DK's method by adding the <base> tag above all my external files in the <head> and it's working perfectly now.

    Thank you both very much.

    Kind regards,

    cL.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •