3

I have website with 3000 pages in HTML. Now I have migrated to CMS which does not have any extension in URL. I kept the same structure of URL as I had in HTML site.

For Example:

HTML site URL :

www.site.com/xyzdirectory/abc.html

CMS site

www.site.com/xyzdirectory/abc

For that, I am using below .htaccess code.

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

But It does not match directory structure.

Tharif
  • 13,794
  • 9
  • 55
  • 77
Suraj
  • 576
  • 2
  • 10
  • 37

1 Answers1

1

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

www.site.com/xyzdirectory/abc.html 

to

 www.site.com/xyzdirectory/abc 

you simply have to alter the last line from the code above to match the filename:

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

Refer this and this SO post for more

Community
  • 1
  • 1
Tharif
  • 13,794
  • 9
  • 55
  • 77
  • I have moved from simple HTML site to Concrete5 CMS. Will it still work ? There are around 3000 pages and 25 directories. Will it match same structure without .html ? I mean redirect. – Suraj Jul 16 '15 at 05:07
  • What could be the rule , if my site is in subdirectory and this rule only applies to subdirectory ? e.g. www.mainsite.com/demosite – Suraj Jul 16 '15 at 05:10
  • I mean I have another site in root directory, where I don't want to apply this rule. This rule only work for the sub directory , where I have demo site, – Suraj Jul 16 '15 at 05:15
  • you can do something..create a subdirectory and place htaccess codes within them and give it a try ! Do not try them directly to your files if you are so much worried about.Just try it out and if confident just go ahead with target subdirectory ! – Tharif Jul 16 '15 at 05:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83384/discussion-between-user3288891-and-utility). – Suraj Jul 16 '15 at 05:43