Very quick htaccess question!

Discussion in 'Apache' started by hasen, Oct 29, 2009.

  1. #1
    I simply want to rewrite a hash # or other symbol to a question mark via htaccess. So any hash in the URL anywhere should internally rewrite to a ?. All I want is to remove ? from the URL really.

    Thanks in advance.
     
    hasen, Oct 29, 2009 IP
  2. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you're talking about the hash like http://forums.digitalpoint.com/showthread.php?t=1551340#post12786954 it can't be done. Those are set by the browser and are not be read by Apache.

    Your best bet would be to catch it using JavaScript and redirect that way.
     
    chadsmith, Oct 29, 2009 IP
  3. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hasen, Oct 29, 2009 IP
  4. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah gotcha. Short answer is yes, as long as you're not using the hashmark.

    I do a similar thing on detectmobilebrowser.com for the redirection service: http://detectmobilebrowser.com/cnn.com|m.cnn.com

    Here's an example of what your rewrite rule might be:

    RewriteRule ^([^\|]+)\|(.+)$ /$1?$2 [L]
    Code (markup):
    That will take anything like

    yoursite.com/index.php|foo=bar

    and redirect it to

    yoursite.com/index.php?foo=bar

    Change \| to another character if you want to use a comma or something else.
     
    chadsmith, Oct 29, 2009 IP
  5. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hmm it still doesn't seem to work. The URL is of the format:

    
    [url]http://www.domain.com/subpage/page?query1=0&query2=0[/url]
    Code (markup):
    If I insert the URL as:

    [url]http://www.domain.com/subpage/page\query1=0&query2=0[/url]
    Code (markup):
    using your htaccess code it doesn't work. The URL returns 0 results so the query is not being read.
     
    hasen, Nov 2, 2009 IP
  6. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you're using the htaccess above you'll want the URL to be

    http://www.domain.com/subpage/page|query1=0&query2=0
     
    chadsmith, Nov 2, 2009 IP
  7. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Using | results in page not found at all.
     
    hasen, Nov 3, 2009 IP
  8. partysoft

    partysoft Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    it's something about this var {QUERY_STRING}

    note that the #ABC it's a book mark and is threated the same way as the GET vars so i think it belongs to the query string and it's not even parsed by mod rewrite in this case...

    check this list
    Mod_Rewrite Variables, from Source

    * TIME – %04d%02d%02d%02d%02d%02d
    * HTTPS – flag ? "on" : "off"
    * TIME_DAY
    * TIME_SEC
    * TIME_MIN
    * TIME_HOUR
    * TIME_MON
    * TIME_WDAY
    * TIME_YEAR
    * IS_SUBREQ – (main ? "true" : "false");
    * PATH_INFO – path_info;
    * AUTH_TYPE – ap_auth_type;
    * HTTP_HOST – lookup_header("Host", ctx);
    * SERVER_NAME – ap_get_server_name(r);
    * REMOTE_ADDR – connection->remote_ip;
    * SERVER_ADDR – connection->local_ip;
    * HTTP_ACCEPT – lookup_header("Accept", ctx);
    * THE_REQUEST – the_request;
    * API_VERSION – "%d:%d",MODULE_MAGIC_NUMBER_MAJOR,MODULE_MAGIC_NUMBER_MINOR);
    * HTTP_COOKIE – lookup_header("Cookie", ctx);
    * SERVER_PORT – ap_get_server_port(r);
    * REMOTE_HOST
    * REMOTE_NAME, NULL);
    * REMOTE_PORT - r->connection->remote_addr->port
    * REMOTE_USER - user;
    * SCRIPT_USER - "<unknown>";
    * APR_FINFO_USER
    * REQUEST_URI - uri;
    * SCRIPT_GROUP - "<unknown>";
    * REMOTE_IDENT - ap_get_remote_logname(r);
    * HTTP_REFERER - lookup_header("Referer", ctx);
    * QUERY_STRING - args;
    * SERVER_ADMIN - server->server_admin;
    * DOCUMENT_ROOT - ap_document_root(r);
    * HTTP_FORWARDED - lookup_header("Forwarded", ctx);
    * REQUEST_METHOD - method;
    * HTTP_USER_AGENT - lookup_header("User-Agent", ctx);
    * SCRIPT_FILENAME - same as request_filename
    * REQUEST_FILENAME - same as script_filename
    * SERVER_PROTOCOL - protocol
    * SERVER_SOFTWARE - ap_get_server_banner();
    * HTTP_PROXY_CONNECTION - lookup_header("Proxy-Connection", ctx);
     
    partysoft, Nov 5, 2009 IP