[wp-hackers] Rewrite rule for pages from old site
Brenda Egeland
brenda at redletterdesign.net
Fri Jun 22 14:51:37 UTC 2012
Thanks Mika and Otto. I think .htaccess is the way to go, because I want the 301 code to get the search engines to update to the new urls. I think I misunderstood something I read somewhere that said add_rewrite_rule was the preferred method. Now I understand it's for modify the permalink structure, not every case of rewrite rules (such as mine).
fyi, the new urls are generally /sermon/what-ever-the-title-is , but I can't see a way to rewrite those urls given the existing site's url structure (sermonYYYYMMDD.php).
Brenda Egeland
Red Letter Design
www.RedLetterDesign.net
301-260-7545
On Jun 22, 2012, at 10:42 AM, wp-hackers-request at lists.automattic.com wrote:
>
> Message: 2
> Date: Fri, 22 Jun 2012 08:13:53 -0500
> From: Mika A Epstein <ipstenu at ipstenu.org>
> Subject: Re: [wp-hackers] Rewrite rule for pages from old site
> To: wp-hackers at lists.automattic.com
> Message-ID: <0FD1E6D1-26B6-4E70-A3BE-A6096D1F6F70 at ipstenu.org>
> Content-Type: text/plain; charset=us-ascii
>
> Why not just do it in .htaccess directly?
>
> RewriteRule ^sermons/([0-9]{4})([0-9]{2})([0-9]{2}).php?$ /sermon/$1/$2/$3?post_type=sermon [L,R=301]
>
> (Caveat - Elf is still on that first cuppa)
>
> Though why do you need the extra post_type on the end? The new CPT URLs should be /cpt/title/ normally, you don't generally push YMD in there (I know you can, but the guy who wrote the plugin for it dropped support because it was somewhat a bad idea).
>
> ----
> Mika A Epstein (aka Ipstenu)
> http://ipstenu.org | http://halfelf.org
>
> ------------------------------
>
> Message: 3
> Date: Fri, 22 Jun 2012 08:23:22 -0500
> From: Otto <otto at ottodestruct.com>
> Subject: Re: [wp-hackers] Rewrite rule for pages from old site
> To: wp-hackers at lists.automattic.com
> Message-ID:
> <CAD-Fghz9XH54Nyx2XEfh5HF=Zq=xdMv1vuxtcq2zVPxP=dnKSg at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Fri, Jun 22, 2012 at 8:03 AM, Brenda Egeland
> <brenda at redletterdesign.net> wrote:
>> Sermon is a custom post type. I've tried add this to my functions.php for a custom rewrite rule:
>>
>> ?add_rewrite_rule(
>> ? ?'^/sermons/sermon([0-9]{4})([0-9]{2})([0-9]{2})\.php?',
>> ? ?'$matches[1]/$matches[2]/$matches[3]?post_type=sermon',
>> ? ?'top'
>> ?);
>>
>> But I keep getting a sorry...not found. I've tried resaving the permalinks in the Settings panel, and still no luck.
>
> That isn't how rewrite rules work.
>
> You're trying to rewrite the old .php based URL into the new "pretty"
> url, but what a rewrite rule in WP does is to convert a "pretty" URL
> into a "default" URL. Default is that thing with ?p=123&year=2012 and
> so forth.
>
> In other words, you can do what you want, but the second part of the
> rewrite rule needs to be "non-pretty".
>
>
> ?add_rewrite_rule(
> ? ?'^/sermons/sermon([0-9]{4})([0-9]{2})([0-9]{2})\.php?',
> ? ?'index.php?post_type=sermon&year=$matches[1]&month=$matches[2]&day=$matches[3]',
> ? ?'top'
> ?);
>
> Or something like that. Didn't test it specifically, might be wrong.
>
> But that won't redirect the old URL to the new one, that will just
> make the old URL work and show the proper content.
>
>
> If you're wanting to actually REDIRECT from the old format to the new
> one, then you're doing it wrong. add_rewrite_rule can't do that
> directly. (Well, it *can*, it's just a bit pointless to do it that
> way). If you want to redirect from the old to the new, then putting a
> RewriteRule directly into the .htaccess (as Mika suggested previously)
> is the simpler and easier way.
>
> -Otto
>
>
More information about the wp-hackers
mailing list