skip to Main Content

I have a website in HTML and I have this link http://html-website.com/CA_NutritionIncentiveProgram.htm which I would like to redirect to https://wordpress-website.com/ca_nutritionincentiveprogram

I have this on my htaccess file but its not working

<IfModule mod_rewrite.c>
# Redirect non WordPress pages to corresponding post
RewriteEngine On
RewriteBase /
RewriteRule ^/CA_NutritionIncentiveProgram/.htm$ https://wordpress-website.com/ca_nutritionincentiveprogram [R=301,L]
</IfModule>

When I load this HTML site http://html-website.com/CA_NutritionIncentiveProgram.htm it redirects me to the wordpress site but with the .htm included (https://wordpress-website.com/ca_nutritionincentiveprogram.htm)

Here is what I have recently (source: RavinderSingh13)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^html-website.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.html-website.com$
    RewriteRule (.*)$ http://www.wordpress-website.com.com/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^/(ca_nutritionincentiveprogram)/?$ [NC]
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI}.html [NE,L]
</IfModule>

Any help

2

Answers


  1. Could you please try following, based on your shown samples only. Please make sure you clear cache of your browser before testing your URLs. Also in you need not to put R=301 else it will rewrite that URL in browser to new one(which we obviously don’t want to show users).

    RewriteEngine ON
    RewriteCond %{REQUEST_URI} ^/(.*ca_nutritionincentiveprogram)/?$ [NC]
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*) http://%{HTTP_HOST}/%1.html [NE,L]
    
    Login or Signup to reply.
  2. Your orignal rule is fine and should work if used in server.config context. If you want to marke it work in htaccess then you need to remove the leading slash because RewriteRule directive uses a relative path (starting without /) in htaccess .

    <IfModule mod_rewrite.c>
    # Redirect non WordPress pages to corresponding post
    RewriteEngine On
    RewriteBase /
    RewriteRule ^CA_NutritionIncentiveProgram.htm$ https://theappliancejudge.co.uk/ca_nutritionincentiveprogram [R=301,L,NC]
    </IfModule>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search