htaccess - Wordpress permalink, stop redirection

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

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:

.html

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

.html
or
.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.

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/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/test/1/mypost-teste21.html
or
http://www.mysite/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 asked Sep 5, 2011 at 11:29 Pedro LobitoPedro Lobito 1031 silver badge4 bronze badges 9
  • Can copy/paste your .htaccess? – Whiler Commented Sep 5, 2011 at 11:32
  • default .httacess for wordpress permalinks - pastebin/3EZSTD9p – Pedro Lobito 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. – Pedro Lobito 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. – Pedro Lobito Commented Sep 5, 2011 at 11:41
 |  Show 4 more comments

4 Answers 4

Reset to default 1

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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745206218a4616604.html

相关推荐

  • htaccess - Wordpress permalink, stop redirection

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

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信