• Resolved Igloo32

    (@igloo32)


    Hi guys,

    I have a client with an old WordPress site which was based on the /?p=xx permalink structure. That has now been redirected to my server and I need to set the htaccess file for 301s.

    I had initially thought I could use a redirect 301 ie:
    redirect 301 /?p=1 http://www.xxx.com/new-structure

    But the ? in the mix seems to be causing a bit of an issue, they work fine if I remove it.

    I have also tried doing the method using RewriteCond as below too but that confuses the server more and brings it down!

    RewriteCond %{HTTP_HOST} ^www.xxx.com$
    RewriteRule ^?p=1(/?|\.html?)$ http://www.xxx.com/new-structure [R=301,NC,L]

    Any ideas… I’m pulling out the last bit of hair I have 🙂

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Try this at the top of your .htaccess file.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule old-url-here/ http://www.new-server.com/new-structure [R=301,L]
    </IfModule>

    Please make sure you have a backup copy of that .htaccess file first.

    Edit: Query string, I always forget the query string…

    It get’s real ugly with the query string.

    <IfModule mod_rewrite.c>
    RewriteCond %{QUERY_STRING} ^p=1$
    RewriteRule (.*) http://www.new-server.com/new-post-url [R=301,L]
    </IfModule>
    Thread Starter Igloo32

    (@igloo32)

    That didn’t work I’m afraid, I’m sure it’s the ? that’s causing the issue as it the normal 301 work correctly without it…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Is mod_rewrite enabled for that directory on your server and directory?

    Easy way to check, just add these lines to the very top.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule send-me-to-cnn/ http://www.cnn.com/ [R=301,L]
    </IfModule>

    And visit http://your-url-here/send-me-to-cnn/ with your web browser.

    Let me know if you get 301’ed to CNN’s web site. I just tried it on one of my sites and that worked.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I’m sure it’s the ? that’s causing the issue as it the normal 301 work correctly without it…

    It’s the query string. That’s why I modified my original post.

    Thread Starter Igloo32

    (@igloo32)

    That worked correctly for the send-me-to-cnn rule and the RewriteEngine on code was already implemented when I first set the site up.

    Then I tried your edited post and it works perfectly 🙂

    Do you know if I could implement the code with a HTTP_HOST condition so that only traffic from a specified domain works with the redirects? I only ask as it’s a multisite installation and if another domain gets pointed to the server it might conflict if they have existing similar permalinks.

    RewriteCond %{HTTP_HOST} ^www.xxx.com$

    Thank you ever so much for your help too, much appreciated!

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    It’s untested but I think this may work.

    <IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} ^www\.xxx\.com$
    RewriteCond %{QUERY_STRING} ^p=1$
    RewriteRule (.*) http://www.new-server.com/new-post-url [R=301,L]
    </IfModule>

    Give that a try.

    Thread Starter Igloo32

    (@igloo32)

    That seems like it’s working on my test server, will try it out on the live one later on.

    Thank you again so much for your help 🙂

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    You’re welcome, glad to help. 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘htaccess and a permalink ?p=xx redirect issue’ is closed to new replies.