WordPress.org

Support

Support » How-To and Troubleshooting » WordPress Overriding htaccess?

WordPress Overriding htaccess?

  • I need to redirect all my .html pages to the corresponding .php page. Everywhere I’ve looked suggests that the following .htaccess code should do it:

    RewriteEngine On
    RewriteRule ^(.*).html$ $1.php

    …But it’s not working. When someone goes to an .html page (that has a corresponding .php page), they get a 404 error.

    Is there anything in the WordPress software, or its htaccess code, that could be preventing this line of code from working?

    Below is my full .htaccess file, FWIW:

    RewriteEngine On
    # Redirect any .html pages to the corresponding .php page
    RewriteRule ^(.*).html$ $1.php
    # add www to the domain name if it's not already there
    RewriteCond %{HTTP_HOST} ^muditajournal.com [nc]
    RewriteRule (.*) http://www.muditajournal.com/$1 [R=301,L,nc]

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • UPDATE: Can anybody offer insights on this?

    Since posting this message, I’ve noticed other strange behavior, e.g., if I password protect a folder within my blog directory using .htaccess, then WordPress overrules and redirects the protected URL to a 404 file not found page, before I ever get a chance to enter the password.

    Your section says that all *.html shall be redirected to according php file. But the WP section says that a file or directory not found should be redirected to /index.php:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    .

    Now the mod_rewrite mechanism always works as a chain. So it might be that your *.html file is being remapped to /index.php because it just doesn’t exist.

    In order to break the chain after having processed “your” directive, you should try to put a [L] behind it; this tells Apache to stop processing rewrite rules for this request.

    See also: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html.en

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress Overriding htaccess?’ is closed to new replies.