Redirecting files with html extension to files without extension (in url)

I recently changed my website url using htaccess so that my urls do not display file extensions. Now my problem is that I created a new xml sitemap, so my url will be without extensions !!! Google’s webmaster tool tells me about a problem with duplicate content! i.e. page and page.html have the same name .... so my question is how to redirect URLs with html file extension to URLs with extension !!! this is an example of my site url with html extension

http://www.shenazhpeyk.co.uk/coding-machines.html

I want to redirect and change it to

http://www.shenazhpeyk.co.uk/coding-machines

To fix the issue using Google Webmaster Tools (provide me the code to use in the htaccess file)

Many thanks

+4
source share
3 answers

Try the following:

Options +FollowSymLinks -MultiViews DirectorySlash Off RewriteEngine On RewriteCond %{SCRIPT_FILENAME}/ -d RewriteCond %{SCRIPT_FILENAME}.html !-f RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.+)\.html$ /$1 [R=301,L] RewriteCond %{SCRIPT_FILENAME}.html -f RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 
+1
source

Found this code too. Not sure if he will do the same. It seems to work for me, as above (for PHP).

 RewriteEngine On # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ /$1 [R=301,L] # Redirect external .php requests to extensionless url RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ /$1 [R=301,L] # Resolve .php file for extensionless php urls RewriteRule ^([^/.]+)$ $1.php [L] 

I wonder what traits should be there or missing?

+1
source

Try adding the following to the .htaccess file in the root directory of the site redirect URLs with the extension .html and delete it.

 RewriteEngine on RewriteBase / #redirect to remove the .html extension RewriteRule ^(.+)\.html$ $1 [L,NC,R=301] 
0
source

Source: https://habr.com/ru/post/1396201/


All Articles