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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts

    301 redirect problem

    Hi - I'm trying to redirect old URLs with variables to new URLs with variables.

    e.g.

    http://www.mysite.com/blog.php?c=My Blog Is Cool

    should redirect to

    http://www.mysite.com/letters.php?blogname=Cool Blog

    The variable on the end is important as I need it to decide which URL should be gone to next. I've only got about 10 URLs to redirect, so I don't need a dynamic script - I'm happy to do it one by one.

    So far I've tried:

    Code:
    Redirect 301 /blog/myblog.php?c=My Blog Is Cool http://www.mysite.com/letters.php?blogname=Cool Blog
    Which doesn't work as it doesn't take into account the URL variables, it just ignores them completely.

    So then I tried adding this:

    Code:
    RewriteCond %{QUERY_STRING} ^c=My Blog Is Cool$ 
    Redirect 301 /blog/myblog.php http://www.mysite.com/letters.php?blogname=Cool Blog
    Which got me one step closer, now I'm redirecting but it's appending the old variables to the end of my URL, and does the redirect regardless of what the old URL was!

    Would really appreciate some help as I'm pulling my hair out!

    Thanks,
    Nicky

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    Hi - I'm trying to redirect old URLs with variables to new URLs with variables.

    e.g.

    http://www.mysite.com/blog.php?c=My Blog Is Cool

    should redirect to

    http://www.mysite.com/letters.php?blogname=Cool Blog

    The variable on the end is important as I need it to decide which URL should be gone to next. I've only got about 10 URLs to redirect, so I don't need a dynamic script - I'm happy to do it one by one.

    So far I've tried:

    Code:
    Redirect 301 /blog/myblog.php?c=My Blog Is Cool http://www.mysite.com/letters.php?blogname=Cool Blog
    Which doesn't work as it doesn't take into account the URL variables, it just ignores them completely.

    So then I tried adding this:

    Code:
    RewriteCond %{QUERY_STRING} ^c=My Blog Is Cool$ 
    Redirect 301 /blog/myblog.php http://www.mysite.com/letters.php?blogname=Cool Blog
    Which got me one step closer, now I'm redirecting but it's appending the old variables to the end of my URL, and does the redirect regardless of what the old URL was!

    Would really appreciate some help as I'm pulling my hair out!

    Thanks,
    Nicky
    the problem is urlencoding, you can't use spaces or other things not allowed in a url.
    must be something like My%20Blog%20is%20Cool
    will work with both regex and RedirectPermanent but need to be like this:

    Code:
    Redirect 301 /blog/myblog.php?c=My%20Blog%20Is%20Cool http://www.mysite.com/letters.php?blogname=Cool%20Blog
    best regards

  • Users who have thanked oesxyl for this post:

    nickyfraggle (04-01-2011)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hi - Thanks for your help.

    I have tried it without spaces (using hyphens or %20 inbetween) but it still doesn't work.


    Nicky

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    Hi - Thanks for your help.

    I have tried it without spaces (using hyphens or %20 inbetween) but it still doesn't work.


    Nicky
    redirection work without normal links? where you use this in a .htaccess file? the server see the .htaccess?
    for last two questions, is simple to check, put some garbage in .htaccess and if you get a 500 error it work,
    for first, try a normal redirection from one page to another, to fake page, contact to info.

    best regards

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hi - Yes the server is definitely seeing the htaccess file. Other parts of it are working no problems.

    I think the main problem I'm having now is getting it to recognise the variables on the end of the first URL. I can redirect to a new URL with variables (like you said with no spaces), but if I put variables in the first URL it doesn't work.

    Very frustrating!

    My code now looks like:
    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    
    Redirect 301 /blog/blogger.php http://www.mysite.co.uk/blog/myblog.php?c=My%20Blog%20is%20Cool
    This works and redirects correctly, but I really need it to work with variables in the first URL too:
    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    
    Redirect 301 /blog/blogger.php?b=12 http://www.mysite.co.uk/blog/myblog.php?c=My%20Blog%20is%20Cool
    This doesn't work!

    Thanks again for all your help. I've been all over the internet looking.

    It's appreciated.

    Nicola

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    Hi - Yes the server is definitely seeing the htaccess file. Other parts of it are working no problems.

    I think the main problem I'm having now is getting it to recognise the variables on the end of the first URL. I can redirect to a new URL with variables (like you said with no spaces), but if I put variables in the first URL it doesn't work.

    Very frustrating!

    My code now looks like:
    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    
    Redirect 301 /blog/blogger.php http://www.mysite.co.uk/blog/myblog.php?c=My%20Blog%20is%20Cool
    This works and redirects correctly, but I really need it to work with variables in the first URL too:
    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    
    Redirect 301 /blog/blogger.php?b=12 http://www.mysite.co.uk/blog/myblog.php?c=My%20Blog%20is%20Cool
    This doesn't work!

    Thanks again for all your help. I've been all over the internet looking.

    It's appreciated.

    Nicola
    i don't think you can mix RewriteCond and Redirect to pass arguments.
    Look to this two ways:

    http://httpd.apache.org/docs/2.2/rew...tml#setenvvars

    http://httpd.apache.org/docs/2.2/rewrite/advanced.html

    best regards

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    I see what you mean, so I removed this line:

    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    It still works in the same way so it wasn't doing anything like you suggested.

    How would I get the redirect to notice the variables on the end of the first URL (the one to redirect from)? I don't need to do anything with the variables or pass them on, I just need it to recognise the whole URL and redirect.

    Thanks,

    Nicola

    p.s I'm reading through your links...tough going!!

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    I see what you mean, so I removed this line:

    Code:
    RewriteCond %{QUERY_STRING} ^c=My%20Blog$
    It still works in the same way so it wasn't doing anything like you suggested.

    How would I get the redirect to notice the variables on the end of the first URL (the one to redirect from)? I don't need to do anything with the variables or pass them on, I just need it to recognise the whole URL and redirect.

    Thanks,

    Nicola

    p.s I'm reading through your links...tough going!!
    try this:

    Code:
    RewriteCond %{QUERY_STRING} ^c=(.*)$
    RewriteRule ^blog\.php$  letters.php?blogname=%1 [R=301,L]
    best regards

  • Users who have thanked oesxyl for this post:

    nickyfraggle (04-07-2011)

  • #9
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Wow that's really close! It works, but my original URL is in a sub directory not in the root and I can't get it to look for blog.php anywhere else other than the root?

    I tried:
    Code:
    RewriteCond %{QUERY_STRING} ^c=(.*)$
    RewriteRule ^/blog/blog\.php$  letters.php?blogname=%1 [R=301,L]
    but no luck. I really do hate htaccess!

    Nicola

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    Wow that's really close! It works, but my original URL is in a sub directory not in the root and I can't get it to look for blog.php anywhere else other than the root?

    I tried:
    Code:
    RewriteCond %{QUERY_STRING} ^c=(.*)$
    RewriteRule ^/blog/blog\.php$  letters.php?blogname=%1 [R=301,L]
    but no luck. I really do hate htaccess!

    Nicola
    this one?

    Code:
    RewriteRule ^blog\/blog\.php$  letters.php?blogname=%1 [R=301,L]
    best regards

  • Users who have thanked oesxyl for this post:

    nickyfraggle (04-07-2011)

  • #11
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    It works!! You are an angel!!

    I do have one really small problem now - spaces don't work out right. When redirected the become:

    My%2520Blog

    In the URL they are entered:

    My%20Blog

    You have been very helpful and I really appreciate your help.

    Nicola

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    It works!! You are an angel!!

    I do have one really small problem now - spaces don't work out right. When redirected the become:

    My%2520Blog

    In the URL they are entered:

    My%20Blog

    You have been very helpful and I really appreciate your help.

    Nicola
    %2520 means after decoding %20, you have % somewhere?

    Edit: yes you have,
    the url in the address bar: "My%20Blog", use "My Blog" instead


    best regards

  • #13
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    It even does it if I remove the %20 from the URL and just leave the space e.g.My Blog still goes to My%2520Blog.

    I'm happy to replace the space with a hyphen if that helps?

    Nicola

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nickyfraggle View Post
    It even does it if I remove the %20 from the URL and just leave the space e.g.My Blog still goes to My%2520Blog.

    I'm happy to replace the space with a hyphen if that helps?

    Nicola
    clear the browser cache and try again, i can bet is a browser problem,
    but yes, a '-' would be better

    best regards

  • #15
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Ok I'll clear my cache. I'm looking up how to add a hyphen to replace the space in the new URL.

    This .htaccess stuff is a real headache! Really appreciate your time today.

    Nicola


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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