• Resolved anjx

    (@anjx)


    Hi,
    I want add the .html extension on just only page.
    site.com/contact
    to
    site.com/contact.html

    My .htaccess is:

    # ==========================================================
    # Rewrite old link
    # ==========================================================
    RewriteRule ^contact$ /subdirectory/contact\.html [R=301,L]
    # ==========================================================
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /subdirectory/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /subdirectory/index.php [L]
    </IfModule>
    
    # END WordPress

    The code: RewriteRule ^contact$ /subdirectory/contact\.html [R=301,L]
    make me correct url site.com/subdirectory/contact.html but with 404 error.
    Can you help me please?

Viewing 10 replies - 1 through 10 (of 10 total)
  • That is a valid rewrite rule. Can you confirm whether the page you are redirecting to exists? For example, if you visit example.org/subdirectory/contact.html, does that page load?

    Thread Starter anjx

    (@anjx)

    I have create a page in wordpress with “contact” names. The default permalink is subdirectory/contact without html, so if I go to contact.html, I receive 404 error.

    OK, so you’ll want to reverse your rule.

    RewriteRule ^subdirectory/contact\.html$ /contact [R=301,L]

    This will redirect the user to the page that exists.

    Thread Starter anjx

    (@anjx)

    No, I want redirect to contact.html

    What problem are you trying to solve with this redirect/rewrite?

    Thread Starter anjx

    (@anjx)

    I want the contact page with html extension and the gallery page without html extension.
    I’ve tried to put html extension on all page with php. So I’ve tried to remove html extension to gallery.html page with htaccess rule, but I have the same problem: 404 error. Seem that if I change the default rule by htaccess, I receive 404 error.
    I tried also custom permalink plugin and it works fine, but I don’t want use a plugin for this issue.

    Sounds like you just want WordPress to respond when contact.html is requested. You can accomplish that by adding a rewrite rule to WordPress:

    add_rewrite_rule(
        '^contact.html$',
        'index.php?page_id=4',
        'top'
    );

    Where page_id should be the ID of your contact page.

    Thread Starter anjx

    (@anjx)

    I think that it’s the right way. I’ve added this code with the page_id of my contact page, but not work, when I go to the contact page remains without html extension ??

    Did you put this code in a plugin or in your theme’s functions.php file? Also, visit the “Permalinks” page under “Settings” to flush WordPress’ rewrite rules and load your new rule into the database.

    Thread Starter anjx

    (@anjx)

    Ok, thank you very much. I found solution. My template have 2 function.php. Inserting the code in the function.php inside “framework” folder, the code works fine ?? 10 star for you ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Rewriterule give me always 404 error’ is closed to new replies.