Question

I switched my website to wordpress but now url link end with slash(/) instead of .html and i don't wanted to lose my google index so After banging my head around here and there , I have finally found a solution. i created .htaccess rule that will work globally for every page.

I just updated the .htaccess file in root with below code:

RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]

Now any URL like this: /features/cart/ will automatically forward to /features/cart.html Everything was working fine but now i am getting 404 error on those page which already have .html extension. Please advice asap, because i am loosing my indexing and keyword ranking.

Here below is the actual code of .htaccess file:

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f

# Rewrite rule for appending .html
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]



redirect 301 /about_us.html /about.html
redirect 301 /about/ /about.html

</IfModule>

# END WordPress

Site name: dailydealbuilder.com

Was it helpful?

Solution

Try reordering your rules:

Redirect 301 /about_us.html /about.html
Redirect 301 /about/ /about.html

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.+?)/$ $1.html [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.+?)\.html$ index.php/$1 [L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

</IfModule>
# END WordPress
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top