regex - Redirect and Rewrite to remove .html from url -


i have basic rewrite rule i've been banging head against wall trying achieve. have static html site want pretty urls for.

so, want /something serve /something.html , want redirect (externally) /something.html /something not penalized on seo hosting duplicate content.

i don't want use multiviews , don't want use <rel cannonical="">

this have.

rewriterule ^(.*)\.html$ /$1 [r=302,l]  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewritecond %{request_filename}\.html -f rewriterule ^(.*)$ $1.html [l] 

it results in infinite redirect loop.

it seems me first rule keeps matching after requested url doesn't end in .html.

yes rules cause redirect loop due use of request_uri (via rewriterule) changes after application of rule.

you can use:

    rewritecond %{the_request} \.html [nc]     rewriterule ^(.*)\.html$ /$1 [r=302,l]      rewritecond %{request_filename} !-d     rewritecond %{request_filename} !-f     rewritecond %{request_filename}\.html -f     rewriterule ^(.*)$ $1.html [l] 
  • the_request variable represents original request received apache browser , doesn't overwritten after execution of rewrite rules.

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -