TELA
TELA

Reputation: 41

WordPress conditional rewrite rule based on date and requested url

Im trying add a rewrite rule for an old website that just undergone some renovation.

so far the rewrite rule is like /%year%/%monthnum%/%day%/%post_id%.html and now just need to change that to /%postname%.html

The issue is, since this is a non-English Unicode web portal, a typical old %postname%.html be like /%E0%A4%95%E0%A5%8D%E0%A4%AF%E0%A5%8B%E0%A4%82%20%E0%A4%95%E0%A5%81%E0%...html

So don't like that non-english string in url for old contents. And for new contents, we manually set English post slug from now on.

Is there any workaround like matching url and apply rules based on that like below?

if (preg_match("/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/(.+\.html)/",$uri)) {
    
           // appaly rewrite rule  `/%year%/%monthnum%/%day%/%post_id%.html`
        
    }elseif (preg_match("/^([^/]+).html)/",$uri)){
        
          // apply rewrite rule /%postname%.html
    }

And I also need to manipulate the permalink accordingly for contents published before and after(a date)

Any help please..

Upvotes: 0

Views: 116

Answers (0)

Related Questions