Forum Moderators: phranque
I want to start using Wordpress, and I want to be able to redirect Cutenews news post URLs. I was trying to use the following code that I found, but it doesn't work:
# redirect the old cutenews articles
RewriteCond %{QUERY_STRING} (.*)(subaction¦start_from)(.*)id=([0-9]+)(.*)
RewriteRule ^.* http://www.example.com/cutenewsredirect.php?article=%4 [L] This sends the URL to a php script that then redirects to the new post on Wordpress, although at the moment I've just got it pointing at the index of my site to test it.
The URL I'm entering in the php script is:
http://www.example.co.uk/index.php?subaction=showcomments&id=1224185187&archive=&start_from=&ucat=&
however, unless you strip it down to this, it doesn't work:
http://www.example.co.uk/index.php?id=1224185187
How can I get it so it just uses the id out of the first URL for the redirect, no matter what else is around it?
I'm not particularly a coder or anything so please explain clearly. :)
Thanks!
[edited by: jdMorgan at 2:20 am (utc) on April 13, 2009]
[edit reason] example.com, example.co.uk [/edit]
# redirect the old cutenews articles
RewriteCond %{QUERY_STRING} &?id=([0-9]+)&?
RewriteRule ^.*$ http://www.example.co.uk/cutenewsredirect.php?article=%1 [L]
Jim
[edited by: jdMorgan at 2:21 am (utc) on April 13, 2009]
I did some messing around with the URL to see what could be stopping it from redirecting, and it redirects fine so long as the = between "subaction=showcomments" isn't there...
How do I add to the beginning of the regex that I want it to ignore this = so that it redirects with it there?
Thank you!
Be sure to completely flush your browser cache before testing any new or modified server-side code (e.g mod_rewrite, PERL, or PHP code).
If this does not help, then you have another rule or directive which is interfering with your rule. Find it and correct it.
Jim
I have nothing else in the .htaccess file... I wondered if it was something in the cutenewsredirect.php file that could be causing the problem, but I don't see why:
<?php
{
case "1224185187":
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.example.co.uk");
break;
}?>
I'm not sure what else to look for in any file!
Thanks. :)
Tasha
Now you reveal the file contains a 301 redirect to the root of the site. So, requests are returned a 302 redirect to a script and the script sends a 301 redirect to the root. That is a problem.
That's obviously not what you want, and I am not quite sure what you actually want - in terms of both URLs used out on the web, and internal names of files inside the server, however it is likely that the first thing is that the 302 redirect should be a rewrite.
The script will then need to capture the value in the parameter and use it to populate the target URL. Testing by redirecting to the root is a good start here though.
When I searched for some help on redirecting Cutenews URLs I got the two things that I have been working with... the RewriteCond... etc. in the .htaccess and the cutenewsredirect.php code, but obviously they don't work entirely.
What I want is to be able to redirect URLs. I want to start using Wordpress instead of Cutenews on my site, and there's several posts I'd like to re-post on Wordpress, and have the original Cutenews URLs redirect to the new post on Wordpress when someone tries to access them:
eg:
http://www.example.co.uk/index.php?subaction=showcomments&id=1224185187&archive=&start_from=&ucat=&
will redirect to:
http://www.example.co.uk/newpost/
I hope this explains it? And of course I'd love it if any help could be explained so I can understand further. :)
Thank you,
Tasha
[edited by: Tasha25 at 8:44 pm (utc) on April 13, 2009]
All I needed to do was add:
RewriteEngine On
into the .htacess code:
# redirect the old cutenews articles
RewriteEngine On
RewriteCond %{QUERY_STRING} &?id=([0-9]+)&?
RewriteRule ^.*$ http://www.example.co.uk/cutenewsredirect.php?article=%1 [L]
Thank you for all the help anyway! :) And I'll certainly be taking a look at the Regex tutorial as suggested.
Tasha