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.

migrated from stackoverflow.com Sep 7 '11 at 3:10

This question came from our site for professional and enthusiast programmers.

  • Can copy/paste your .htaccess? – Whiler Sep 5 '11 at 11:32
  • default .httacess for wordpress permalinks - pastebin.com/3EZSTD9p – Pedro Lobito Sep 5 '11 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 Sep 5 '11 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. – Pedro Lobito Sep 5 '11 at 11:39
  • Try post a question there and you'll understand why I've posted here - I've deleted the other question. – Pedro Lobito Sep 5 '11 at 11:41

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! – Pedro Lobito Sep 9 '11 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. – Pedro Lobito Sep 8 '11 at 12:59
  • For me worked great because it was a 404 I was looking for:) Thank you:) – viery365 Nov 4 '16 at 14:38

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. – Pedro Lobito Sep 5 '11 at 11:42
  • I appreciate your help but it didn't work, still redirecting. – Pedro Lobito Sep 5 '11 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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