is there an easy way of automatically adding text to end of url

Discussion in 'PHP' started by monkeyclap, Feb 9, 2010.

  1. #1
    hi, here's the issue
    i have a number of pages with the term "q=" in it for the search results, but i want to focus/scroll users automatically to an element, and not load top the page.
    quesiont is, is there a quick way of doing this on .htaccess/php or similar?
    please help, and thanks in advance.
     
    monkeyclap, Feb 9, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You can do soo, with simply using html:

    If I had a page and it's url was: site.com/google.php?q=term

    And I had the following code tags around the content I want to specifically focus/scroll users I'd add:

    <A NAME="results">You've scrolled to the results content!</A>
    Code (markup):
    Then call it by: site.com/google.php?q=term#results and it will scroll down to that.

    Please, refer to the following for more info:

    http://www.htmlcodetutorial.com/linking/_A_NAME.html

    Or.

    Can be achieved much faster/dynamically using jQuery.
     
    danx10, Feb 9, 2010 IP
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    hi there, thanks for the reply

    but i was after something more dynamic as i have a lot of pages and don't want to add "#results" manually to edit all links.

    is there a way of redirecting something like "site.com/google.php?q=term" to "site.com/google.php?q=term#results"

    because all pages end in something different, but all include "q=" i was after a solution to recognise that and automatically redirect those links?
     
    monkeyclap, Feb 9, 2010 IP
  4. thorie

    thorie Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    // Inside top of google.php

    if (false === strpos($_SERVER["REQUEST_URI"], "#results") && array_key_exists('q', $_GET) && $_GET['q'] !== "") {
    header("Location: ".$_SERVER["REQUEST_URI"]."#results");
    die;
    }

    // ... rest of google.php goes here

    Untested, but hopefully you get the idea.
     
    thorie, Feb 10, 2010 IP