1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with htaccess

Discussion in 'Programming' started by Nattawat, Jan 15, 2011.

  1. #1
    Hello,

    My domain is accessible via 2 ways:
    http://www.domain.com/
    http://www.domain.com/index.php

    The index.php itself has GET form, so sometimes the URL will be like:
    http://www.domain.com/?var=12345
    http://www.domain.com/index.php?var=12345

    What I want to do with htaccess is to block the URL http://www.domain.com/?var=12345 entirely. If someone tries to access this URL, they will encounter an error response code. No redirection.

    The blockage should only work for that URL, so if the URL is http://www.domain.com/?var=999 then it should work fine.

    I've been trying to search on Google, but I'm out of keywords to find exactly what I want. Thank you in advance.
     
    Nattawat, Jan 15, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Something like this maybe:

    
    if (stripos($_SERVER['REQUEST_URI'],"var=12345") !== false) // looks for var=12345
        {
         // do nothing
        } else {
          header("Location: http://urlToSomeWhere.com"); // send the visitor somewhere 
           exit;
        }
    
    PHP:
     
    MyVodaFone, Jan 15, 2011 IP
  3. Nattawat

    Nattawat Member

    Messages:
    149
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #3
    I'm not sure about this, but can you use PHP code in htaccess?
     
    Nattawat, Jan 15, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    No, you would put this at the top of index.php just after <?php
     
    MyVodaFone, Jan 15, 2011 IP
  5. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #5
    MyVodaFone was suggesting that you add that code to your index.php file, and I think he's right, but his example code isn't really what you asked for. I think what you want is something more like:

    
      if (stripos($_SERVER['REQUEST_URI'],"var=12345") !== false) {
          header("Location: /error_message_page.html", TRUE, 403);
          exit;
      }
    
    Code (markup):
    which sends the HTTP error code "403 - Forbidden" and displays the page in the "Location:" area. Be sure to leave that as a relative URL. Don't add the "http://" there. And remember that this code must be inserted before the page outputs anything else. Good luck!
     
    rainborick, Jan 15, 2011 IP
  6. Nattawat

    Nattawat Member

    Messages:
    149
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #6
    Nattawat, Jan 15, 2011 IP
  7. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #7
    I doesn't matter if its encrypted you can still add your own code on the very first line and the script looks for var=12345 in the url the two urls above are the same, index.php is loading regardless

    <?php
    code
    ?>

    the rest of your script is below
     
    MyVodaFone, Jan 15, 2011 IP