I'm having some hard-time with with WordPress permalinks. WordPress 3.1 seems to force url redirection, ex:

This is the correct post url:


If I go to any of the url's below WordPress is redirecting me to the url above


Basically, what I want to achieve is that WordPress matches the post id, in this case 1, and presents the post content without redirecting users to the correct url. Any ideas on how to achieve this ?

Thank you all!

PS- Please don't move this question to SO WordPress because I've already tried to get an answer there for a couple of days without luck.

  • Can copy/paste your .htaccess?
    – Whiler
    Commented Sep 5, 2011 at 11:32
  • default .httacess for wordpress permalinks - pastebin.com/3EZSTD9p Commented Sep 5, 2011 at 11:36
  • It's not done by .htaccess -- such correction is done by PHP code. It is there to ensure link integrity/consistency (important for SEO purposes). For example -- take this question URL, remove some text from it (or alter it somehow) and submit -- it will redirect to this URL again. Do not know about you .. but this is correct approach in general.
    – LazyOne
    Commented Sep 5, 2011 at 11:37
  • @lazyOne- I'm also sure that this won't be accomplished by .htaccess, but I also don't know what php code to change in order to achieve what I need. Commented Sep 5, 2011 at 11:39
  • Try post a question there and you'll understand why I've posted here - I've deleted the other question. Commented Sep 5, 2011 at 11:41

4 Answers 4


First, I'll say it's beyond me why you'd want to do this, I really don't think it's a good idea, but in any case...

If you look in /wp-includes/canonical.php, you'll see how WP is fighting you on this. The only way I'm aware of to get around it is to go looking for the post yourself based on the post id query var (which should be set and hopefully correct) and resetting the $wp_query global to whatever is found, then manually setting the status header so a 404 isn't sent to the browser.

function wpse27871_404_fakeout() {
    global $wp_query;
    if( $wp_query->is_404 && get_query_var('p') ):
        $this_query = new WP_Query( 'p='.get_query_var('p') );
        if( $this_query->post_count !== 0 ):
            $wp_query = $this_query;
add_action('wp', 'wpse27871_404_fakeout');
  • Milo : your solution works fine, the post is presented to the user even if the url is incomplete, although, the page misses the meta tags keyword and description, that are blank, any idea on how to solve this? thanks! Commented Sep 9, 2011 at 8:51

Since you deleted your previous question here, perhaps somebody already suggested this to you and it doesn't work, but you might try:

remove_filter('template_redirect', 'redirect_canonical');

  • Doesn't work for my purposes, gives me a 404, thanks anyway. Commented Sep 8, 2011 at 12:59
  • For me worked great because it was a 404 I was looking for:) Thank you:)
    – viery365
    Commented Nov 4, 2016 at 14:38

Try after disabling the SEO plugins like Yoast SEO. They usually redirect to nearest possible matched pages instead of throwing it to 404.


This answer doesn't work!

I don't remove it to avoid similar wrong answer. I'll delete it if a good one is post. In your .htaccess, you probably have some RewriteRule which finish with: [L].

To keep the URL, your have to use the proxy parameter: [P,L]

Regarding the default .htaccess you provided Tuga, I'll try like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [P,L]

Like this, the URL are internaly translated (in Apache), and it stays the same in the browser. But, within WordPress, there's maybe other redirections which can affect the URL itself :/

  • Do you mind to exemplify the "use the proxy parameter", thanks. Commented Sep 5, 2011 at 11:42
  • I appreciate your help but it didn't work, still redirecting. Commented Sep 5, 2011 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.