Search code examples
phpwordpresspermalinks

Prevent Wordpress Access From Default Permalinks Structure


I'm trying to disable/prevent wordpress post from old permalinks structure.

Example, I have custom permalink structure like this:

http://blablabla*com/hello-world

But that post still can accessed use old permalinks like this:

http:/blablabla*com/?p=1
http://blablabla*com/2014/09/01/hello-world
http://blablabla*com/2014/08/hello-world

I've tried to remove canonical redirect use this code.

remove_filter('template_redirect', 'redirect_canonical');

Seems work, old permalinks not redirected to my new permalink :) But the problem, :( I want disable other permalinks structure and send 404 error. I don't care about canoncial redirect, because its new site and not yet indexed by search engine.

So, that post only can visited use my current custom permalink, not other structure.

I want check current URL, if URL not equal with current permalink setting, send 404 error.


Solution

  • Originally published inside the question by the author

    I found the solution:
    Get the current request_uri, and get the current post permalink, then preg_match them. So if the post visited by old / ugly permalinks (or default wordpress permalinks structure), send 404 error.