SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with .htaccess redirection

    Hello,

    I have trouble with some links like next one:

    http://localhost/browse?price=DESC&from=87/15/0/


    Can you help me how can I redirect those kind of links to page like: http://localhost/items/

    With "those kind of links", I mean links like:
    http://localhost/browse/?price=DESC&from=87/15/0/
    http://localhost/browse?price=ASC&from=87/15/
    http://localhost/browse?price=ASC&from=87/
    etc.

    Not sure, but looks like the problem is in question mark in url... I tried with

    Redirect 301 ^browse(.*) /items/
    Redirect 301 ^browse(.*)(.*) /items
    .... but no luck.


    Can you help me how can I make redirection to /items/ page please?


    Thank you in advance!

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

    The ? is a reserved character which separates a URI from a query string. This makes handling with mod_alias almost impossible and mod_rewrite requires the use of RewriteCond statements to look into variables other than {REQUEST_URI}.

    Warning: Beware the inappropriate use of (.*) as that's the greatest potential for generating loops (albeit it can't do that - or anything else) in a Redirect statement.

    To redirect from browse to items, Redirect 301 browse /items/ should do (and lose all the information contained in the query strings).

    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

  3. #3
    SitePoint Member bagitahu's Avatar
    Join Date
    Mar 2012
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can add this to you .htaccess :

    Code:
    # Redirect old file path to new file path
    Redirect http://localhost/items/ http://localhost/browse/?price=DESC&from=87/15/0/

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @dklynn,

    I need to redirect anything from http://localhost/browse?price=whatever_is_here to http://localhost/items/.

    Problem is that redirection of only http://localhost/browse is not enough for me in this case.

    I don't know why did not make it with mentioned redirectives, and that's why I need help here.


    @bagitahu, thank you, but I need redirection for another way round, not like you mentioned.


    Pls help
    :-(

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

    Did you bother to read the sticky threads or the tutorial article linked in my signature (there are a large number of sample codes in it, too)? If you can't find the answer at your fingertips, make an attempt and I'll correct it with you (the reason for my "no coding for script kiddies" rule is to help all members to learn).

    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 Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tnx, I manage to do it. I created new directory called browse, with single index.html file in it, that contains redirection to the /items link (on server, html file is treated as php).

    It is not .heaccess solution, but it's quick and it works.


    Tnx!


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
  •