Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Peculiar mod_rewrite question

    Hi there,

    I have a rather strange URL from my client's old website that I need to redirect.

    It goes like this. I need to change this:

    http://www.mrmoco.com/index2.htm?sid.../Rigs/milo.htm

    Into this:

    http://www.mrmoco.com/Products/Rigs/milo.htm

    Basically, I just need to remove this part of the query string: "index2.htm?sidebar.htm&/"

    This rule should obviously only happen if such a string exists within the URL.

    It's not a customary query string. I don't know if that makes any difference, but it has stopped my simplistic solutions from working.

    Any help much appreciated.

    -Victor

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Something along these lines should do the job...

    Code:
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} &/(Products/Rigs/milo.htm)$
    RewriteRule .* /%1? [R=302]
    ...obviously that's pretty specific and will only work for a single url, but to make it more generic you just need to replace the /Products/Rigs/milo.htm part with a Regex pattern. I'm not familiar with the URI design for this project, but I would assume that something like this would be suitable...

    Code:
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} &/([^&]+\.htm)$
    RewriteRule .* /%1? [R=302]

  • Users who have thanked Cags for this post:

    vkloss (08-04-2011)

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That works a charm, thank you very much!

    My only (hypothetical) question is, the rewrite condition will only match .htm files, is that correct? How could I get it to match any type of file? (eg. .PHP, .HTML etc.)

    -Victor

  • #4
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Well you could just remove the \.htm part of the pattern, but this could potentially lead to false positives. A safer approach would probably be to include a whitelist like so \.(htm|php|foo)

  • #5
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Makes sense, thanks for your help!

    -Victor


  •  

    Tags for this Thread

    Posting Permissions

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