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

  1. jonag
    Posted 8 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:

    <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]

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

  2. moshu
    Posted 8 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
    Posted 8 years ago #

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


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

  4. moshu
    Posted 8 years ago #

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

  5. jonag
    Posted 8 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
    Posted 8 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
    Posted 8 years ago #

    No - see here.

  8. jonag
    Posted 8 years ago #

    Thank you both very much!

Topic Closed

This topic has been closed to new replies.

About this Topic