SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    7
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    301 redirect with querystring problem

    hello!
    i just changed my bulletin board from vbulletin to smf everything is going well but now i need to create an .htaccess file to redirect my post url to the new one im trying to test it in xamp first but its not working.
    here is the old link
    http://localhost/zaman/vb/showthread.php?11578
    i want redirect it to
    http://localhost/smf/index.php/topic=11578

    however this post id is varibale

    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^t=([0-9]+)$
    RewriteRule ^/zaman/vb/showthread.php$ /smf/index.php/topic=%1 [R=301,L]
    i tried this code but its not working
    any ideas, or ill lost more than 450k of indexed links in google
    plz help
    thanks in advance

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,312
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by egyzaman View Post
    ^t=([0-9]+)$
    In the example old URL you showed, the query string was just digits, not "t=" digits. Make sure you're clear about what kind of query string you're trying to match.

    Quote Originally Posted by egyzaman View Post
    RewriteRule ^/zaman/vb/showthread.php$ /smf/index.php/topic=%1 [R=301,L][/CODE]
    If this rewrite is in an htaccess file, which I suspect is the case, then you need to remove the leading slash from the pattern.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    7
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for quick reply
    i did as u said sir so the code be like this
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^([0-9]+)$
    RewriteRule ^zaman/vb/showthread.php$ /smf/index.php/topic=%1 [R=301,L]
    its almost done but it gives me that adress
    http://localhost/smf/index.php/topic=11578?11578
    and this result (Numeric request keys are invalid.)
    so i just need to remove the last (?11578)

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,312
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Ahh, yes. The original query string is retained unless you define a new one in the substitution URL, which is as simple as just adding a question mark.

    RewriteRule ^zaman/vb/showthread.php$ /smf/index.php/topic=%1? [R=301,L]
    "First make it work. Then make it better."

  5. #5
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    7
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i tried to make as whaT u said sir bur nothing happend is there another solution?
    because i dont know so much about htaccess and how it works

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,312
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Can you show what your htaccess looks like now?
    "First make it work. Then make it better."

  7. #7
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    7
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yes sir its like this
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^([0-9]+)$
    RewriteRule ^zaman/vb/showthread.php$ /smf/index.php/topic=%1? [R=301,L]

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,312
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    I copy-pasted that code verbatim, and it ran exactly as expected. So there must be something else we're not seeing.
    "First make it work. Then make it better."

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

    ^([0-9]+)$ is matching your entire query string. If you only want the digits, remove your start anchor (the ^).

    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

  10. #10
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    7
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    its now working like a charm with both of u and here is the final code for who want
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ([0-9]+)$
    RewriteRule ^zaman/vb/showthread.php$ /smf/index.php/topic=%1? [R=301,L]
    this code for who changing from vbulliten 4 to smf 2. offcourse u will not save all ur links but it help for the main posts
    thank u for mr jeff and mr dklynn for their help
    and thanks for all


Tags for this Thread

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
  •