WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] .htaccess redirect from generic .html link to .php? (8 posts)

  1. jonag
    Member
    Posted 7 years ago #

    I moved my blog from MT to WP and was able to preserve the permalink structure:

    Old MT permalinks: "domain.com/archives/001234.html"

    New WP permalinks: "domain.com/archives/001234.php"

    But I have not succeeded in creating an htaccess redirect so that people who find a link to one of my old MT posts on Google are automatically sent to the php version of that link. I also want to redirect Google links to my old blog's MT comments, which take the form "domain.com/archives/001234.html#005678", to "domain.com/archives/001234.php" (i.e., I want the comment ID string to be stripped from the URL, and the URL then converted to php format).

    My current .htaccess file (which doesn't work for html-to-php redirection) is:

    code
    <IfModule mod_rewrite.c>
    RewriteEngine On
    # WordPress rules: redirect not-found file or directory to index.php.
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # Redirect any .html page to the corresponding .php page.
    RewriteRule ^(.*).html$ $1.php [L]
    </IfModule>
    /code

    I'd be grateful if anyone could show me how to perform the generic htaccess redirects I'm asking about. Thanks.

  2. moshu
    Member
    Posted 7 years ago #

    Actually, in WP you don't have .php extension on posts, for example. So, how do you get those
    archives/001234.php URIs?

  3. jonag
    Member
    Posted 7 years ago #

    In the options/permalinks section of my WP control panel, I specified the following customized permalink structure:

    /archives/%post_id%.php

    I specified this permalink structure partly because I thought it would make redirects easier to set up.

  4. moshu
    Member
    Posted 7 years ago #

    So, did you try
    /archives/%post_id%.html - if that's what you want?

  5. jonag
    Member
    Posted 7 years ago #

    No, in my ignorance I assumed that only php extensions would work. But I just tried it and it works fine. Does substitution of html for php extensions change the functioning of my WP site?

  6. moshu
    Member
    Posted 7 years ago #

    It shouldn't. All that "extension" is not real - the core files and the template files etc. still are php files and they work. Should I say... hmmm... it's a "virtual extension"? ;)

  7. onocrotalus
    Member
    Posted 7 years ago #

    No - see here.

  8. jonag
    Member
    Posted 7 years ago #

    Thank you both very much!

Topic Closed

This topic has been closed to new replies.

About this Topic