What you’ve created is a loop with the two RewriteRules returning code to active the other. Missing is a line which identifies a {REQUEST_URI} as having been redirected already to prevent the loop (the NC - No Case - flag is also a problem). Try:
[code]#remove file Extension #Redirect extension requests to avoid duplicate content ONLY if not already redirected
RewriteCond %{IS_SUBREQ} false
RewriteRule ^(.+).html$ $1 [R=301,L]
Thank you for the reply.
I tried your code. However, it is not working. The results are same.
If I put extension and then query string og GA Config URL, then it gets redirected to proper page and without extension, I am getting Page Not Found error.
Could you please help me? I am triyng this for so many days but no luck so far.
#remove file Extension
#Redirect extension requests to avoid duplicate content ONLY if not already redirected
RewriteCond %{IS_SUBREQ} false
RewriteRule ^(.+)\.html$ $1 [R=301,L]
#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule .? %{REQUEST_URI}.html [L]
I changed the code slightly (because you don’t need your ^(.*) to capture the {REQUEST_URI}). This code does exactly what you want, i.e., if there had been no internal redirections, the .html is stripped from the {REQUEST_URI} and displayed in the location box (by the R=301) THEN, if the (new) {REQUEST_URI} exists WITH A .html FILE EXTENSION, it will redirect to that html file.
Since this is NOT working, there is something else interfering with your mod_rewrite, probably your GA Config’c code. Please post your entire (mod_rewrite portion) of your .htaccess file and I’ll try to combine (or reorder) as necessary for you to make this work.
Uh, oh! I see the problem! IIS uses one of two M$-peculiar coding languages for its implementation of rewrite directives (only one is relatively similar to Apache’s mod_rewrite). Please note the keyword “relatively” because M$ did not duplicate Apache’s complete functionality with it’s mod_rewrite implementation … and I must guess that Apache’s {IS_SUBREQ} variable is one which is missing.
Years ago, when I realized that mod_rewrite code could be written to NOT loop on a circular redirect, I first created code to mark the redirection with an unique query string. I believe that you MIGHT be able to do that, too, using code like:
[code]RewriteEngine On
# the query string contains "redirect=true"
RewriteCond %{QUERY_STRING} redirect=true
# strip the .html file extension and redirect showing the new {REQUEST_URI}
RewriteRule ^(.+).html$ $1 [R=301,L]
# then, if the new {REQUEST_URI} (via {REQUEST_FILENAME} exists with an html extension
RewriteCond %{REQUEST_FILENAME}.html -f
# redirect the {REQUEST_URI} to {REQUEST_URI}.html (internally)
# I still don't like (.*) for other reasons but IIS may not like {REQUEST_URI}
# ... but use the end anchor, too!
# ( the $ after ^(.*) )
RewriteRule ^(.*)$ $1.html?redirect=true [L][/code]
Please let me know if that words for you as I will not use M$ online but should know when something does work for those in the M$ world. Thank you.