WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Complex redirect - help! (2 posts)

  1. zarkobiz
    Member
    Posted 3 years ago #

    I need to redirect the incoming traffic seeking old permalinks domain.com/blog/?p=123 to domain.com/123 and I don't know how to do it.

    PROBLEM HISTORY:

    1. Initial WP installation in domain.com/blog/
    Initial permalinks /blog/?p=123. This ran for several months

    2. Changed permalinks to /%post_id%/%postname%
    everything worked fine and ran at this config for several months
    Dean's permalinks migration or Smart 404 did an excellent job with no 404s for end users.

    3. Changed the apparent location of the blog to root (Site address URL in general settings). This is how I want to run, but my oldest links from twitter and web sites that look like http://domain.com/blog/?p=123 just return the missing.html page in the root. Some of them that I've created after step 2 were done with just the ID number and without the ?p= and they were still working fine, but now even they are out, so if there's a way to dynamically eliminate the ?p= in the rewrite process, that might be the solution, but I'm too much of a WP newbie and don't know how to do it.

    working old permalink example: http://domain.com/blog/123
    non-working old permalink example: http://domain.com/blog/?p=123

    Now, I was able to make the latter work by putting a separate .htaccess in /blog/:
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
    # END WordPress

    HOWEVER, this disables my /blog/wp-admin (admin login), so I have to remove that .htaccess each time I want to administer the blog, and I've seen some inconsistent results with site losing formatting.

    SEEKING THIS SOLUTION:
    I need to write either a dynamic redirect for the /blog/?p=123 permalinks or a redirect statement for every single one of them (and I don't really have a problem with that, as long as I'm able to make them work.) I have been reading various tutorials and forum posts for days and I didn't make any progress.

    This is the current .htaccess file in the root:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    I'm lost and I need a few lines of code from a redirect/rewrite wiz.
    Please help. Thank you in advance.

  2. zarkobiz
    Member
    Posted 3 years ago #

    Resolved by downloading "Redirection" plugin, then setting up the following redirection rule in it:

    Source URL: /blog/(.*)
    Target URL: /$1

    with Regular Expression (regex) box checked

    For some reason the old default site address domain.com/blog didn't work after this so I have another rule for
    Source URL: /blog
    Target URL: /
    (regular expression box not checked)

Topic Closed

This topic has been closed to new replies.

About this Topic