Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

http://www.mysite.com/test/1/mypost.html

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

http://www.mysite.com/test/1/mypost-teste21.html
or
http://www.mysite.com/test/1/blabla-mypost-example99.html

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.

share|improve this question

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

3 Answers 3

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;
            status_header(200);
        endif;
    endif;
}
add_action('wp', 'wpse27871_404_fakeout');
share|improve this answer
    
It works, thank you Milo :) –  Pedro Lobito Sep 7 '11 at 19:59
    
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

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 :/

share|improve this answer
    
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

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');

share|improve this answer
    
Doesn't work for my purposes, gives me a 404, thanks anyway. –  Pedro Lobito Sep 8 '11 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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