www.webdeveloper.com
Results 1 to 13 of 13

Thread: How o hide GET variable in address bar?

  1. #1
    Join Date
    Dec 2006
    Posts
    115

    Question How o hide GET variable in address bar?

    hi all

    I have a link when clicked display some records from MYSQL database.

    In addressbar i see like http://www.mywebsite.com/students.php?class=12

    I am able to hide the page extension using below code in .htaccess, so now its showing only http://www.mywebsite.com/students?class=12

    with no .php extension. my question is how I can hide the GET variable also. so it will show only http://www.mywebsite.com/students

    and will still display the desired results

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    please reply

    thanks in advance

    regards
    jack
    Last edited by jack001; 08-09-2009 at 03:00 AM.

  2. #2
    Join Date
    Oct 2005
    Posts
    843
    I'm not sure you are actually able to achieve something along those lines. The closet thing i found searching on google led me to this: Source

    Rewrite rules don't actually hide the query string. Rewrite rules pretty much convert seo friendly urls into the actual query string.

    Example .htaccess:
    Code:
    RewriteEngine on 
    RewriteRule ([^/\.]+)/?.html$ viewPage.php?ID=$1 [L]
    The above rewrite rule will allow you to do something like this:

    url reads: yoursite.com/DaniWeb.html

    apache interprets as: yoursite.com/viewPage.php?ID=DaniWeb

    Therefore
    PHP Code:
    <?php
    $id
    =$_GET['ID'];
    echo 
    $id;
    ?>
    will output DaniWeb.

  3. #3
    Join Date
    Aug 2009
    Posts
    1
    maybe a stupid question , but why dont you use the POST method instead? there will be nothing send though th URL...

  4. #4
    Join Date
    Dec 2006
    Posts
    115

    Smile

    It's not a stupid question

    I have add below line in .htaccess

    Code:
    RewriteRule ^/my_page_name-([0-9]+)\d$ my_page_name.php?id=$1
    and a link in my php page like this
    Code:
    <?php echo "my_page_name-".$id."d";?>
    suppose the id is "15" so it will display in addressbar as

    http://www.mywebsite.com/my_page_name-15d

    which is acceptable for me at least

    regards
    Jack

    Quote Originally Posted by Xanthius View Post
    maybe a stupid question , but why dont you use the POST method instead? there will be nothing send though th URL...
    Last edited by jack001; 08-09-2009 at 06:17 AM.

  5. #5
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    The simplest and easiet answer is to switch the form from method=get to method=post and not worry about .htaccess to 'rewritre' the urls to try and hide data.

  6. #6
    Join Date
    Mar 2004
    Posts
    3,056
    I can understand that you'd want to have nice and tidy URLs, but the GET request can actually be a very good thing to keep. It lets people bookmark that particular set of data and makes it available via its URL. If you got rid of it then Google might find the page in question, record the content, and then offer it as a result to someone trying to search for information on that page. If you have lots of different sets of data (in this instance I guessing it's different classes) and they all share the same URL, then Google is likely to offer the page as a potential search match and even show some of the desired content in the little snippets it displays under each link. However because the same URL is used for many sets of data, it's very unlikely that the link will point to your content that Google says is a good match. When the searcher clicks the link they're likely to get completely different content from that indicated in the snippets in Googles listing.
    Last edited by Stephen Philbin; 08-09-2009 at 07:43 PM.

  7. #7
    Join Date
    Dec 2006
    Posts
    115
    I am not gonna have same URL for different sets of dats

    suppose the id is "15" so the URL will be

    http://www.mywebsite.com/my_page_name-15d

    suppose the id is "16" so the URL will be

    http://www.mywebsite.com/my_page_name-16d


    Quote Originally Posted by Stephen Philbin View Post
    I can understand that you'd want to have nice and tidy URLs, but the GET request can actually be a very good thing to keep. It lets people bookmark that particular set of data and makes it available via its URL. If you got rid of it then Google might find the page in question, record the content, and then offer it as a result to someone trying to search for information on that page. If you have lots of different sets of data (in this instance I guessing it's different classes) and they all share the same URL, then Google is likely to offer the page as a potential search match and even show some of the desired content in the little snippets it displays under each link. However because the same URL is used for many sets of data, it's very unlikely that the link will point to your content that Google says is a good match. When the searcher clicks the link they're likely to get completely different content from that indicated in the snippets in Googles listing.

  8. #8
    Join Date
    Feb 2009
    Posts
    162
    I think stupid etc is not right if some one has a question and did knot know about any thing then he ask over here
    so we should reply him in better way.

    I think URL rewrite helps to solve your problem.

    but How if your query sting has space then the how the URL will look like.

  9. #9
    Join Date
    Mar 2004
    Posts
    3,056
    Oh right. Well that's good. It was just this bit of your initial post that gave me the wrong impression.

    Quote Originally Posted by jack001 View Post
    I am able to hide the page extension using below code in .htaccess, so now its showing only http://www.mywebsite.com/students?class=12

    with no .php extension. my question is how I can hide the GET variable also. so it will show only http://www.mywebsite.com/students
    It just looked to me like you were trying to have the same nice, simple, tidy URL cover all values. I have a similair tidy URL thing set up on my site. As far as I can tell, the method I use is unusual. I think most articles I've seen on the subject tend to go for using some form of URL translation; taking parts of a URL and translating it into a GET request (or vice-versa?), but I find my approach much simpler. I just redirect all calls to any file or folder inside directory A back to directory A and then just stick a PHP script in that directory that breaks up the URL into smaller sections and uses those sections for stuff like database queries etc. The end result (how the URLs look to the user) is the same, but the implementation is slightly different.

  10. #10
    Join Date
    Dec 2006
    Posts
    115
    Stephen

    can show me an example of your solution?

  11. #11
    Join Date
    Mar 2004
    Posts
    3,056
    Of course. Here's the Apache directive I use to send all apparently valid addresses back up the directory structure to the PHP file that actually figures out what should be sent to the user based on the URL requested.

    Code:
    ##### ALIASING FOR BLOG ENTRY READING ##########################################
    
    AliasMatch ^/blog/\d{4}-\d\d-\d\d/[^/]+/?$ "/usr/local/apache2/htdocs/blog/index.php"
    
    ##### END ALIASING FOR BLOG ENTRY READING ######################################
    The actual PHP file lives at /blog/index.php on my server. The Apache directive instructs Apache to take any URL that starts /blog/ and then has a DD-MM-YYYY-format date and then a / with pretty-much anything after that and redirect it back to /blog/index.php. Any request for a URL that doesn't match this scheme and does not exist will (rightly) cause Apache to just return a 404.

    So once a URL that initially appears to be valid has been redirected to /blog/index.php the PHP script then breaks the URL up into smaller chunks, validates them and then uses them in an SQL query to retrieve the content. For example my scheme checks to see if the date portion is a valid date and then queries the database for content with a matching date of creation and a title that matches the rest of the URL.

    You'll need to decide how to handle special characters (such as spaces and question-marks) in your URL's title section to avoid unexpected errors, but that's petty much all there is to it.

  12. #12
    Join Date
    Apr 2007
    Posts
    1,664
    What you original post is trying to achieve is impossible. Think about it you want to give the same url

    http://www.mywebsite.com/students

    And expect a script to know it needs to use id 15 or id 2000. How can it possibly know that. The only solution you could use that might come close is similar to suggested already and add the id into the url eg

    http://www.mywebsite.com/students15
    http://www.mywebsite.com/students2000

    And extract the id from the name.

  13. #13
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Quote Originally Posted by SyCo View Post
    OR even...

    http://15.mywebsite.com/students
    http://2000.mywebsite.com/students

    And extract the id from the subdomain

    To confuse matters further...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles