ISAPI Rewrite detect root folder
-
10-06-2021 - |
Question
Using ISAPI Rewrite I'm looking for a way to detect if a given URL contains only one subfolder and then rewriting the URL.
www.mysite.com/Cloud => true
www.mysite.com/Cloud/ => false
www.mysite.com/Cloud/One => false
www.mysite.com/Cloud.xml => false
the result should be the URL added with .html only for the true condition
www.mysite.com/Cloud.html
La solution
Try using the following:
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)$ $1.html [NC,L]
You did not specify if it's a 301-redirect or a rewrite. So in case it's 301-redirect, simply add R=301 in flags.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow