301 redirect does not match directory structure

I have a website with 3000 pages in HTML. Now I have switched to a CMS which does not have an extension in the url. I have kept the same url structure as in the HTML site.

Example:

HTML Site URL:

www.site.com/xyzdirectory/abc.html

      

CMS website

www.site.com/xyzdirectory/abc

      

For this I am using the code below .htaccess

.

RedirectMatch 301 (.*)\.html$ http://www.example.com$1

      

But it doesn't fit the directory structure.

+3


source to share


1 answer


If you want to remove .html extension from html file, for example:

www.site.com/xyzdirectory/abc.html 

      

to

 www.site.com/xyzdirectory/abc 

      



you just need to change the last line from the above code to match the filename:

RewriteRule ^([^\.]+)$ $1.html [NC,L]

      

Refer this and this SO post for more

+1


source







All Articles