.htaccess - htacess: triple rewrite HTTPS + no-WWW + no-.html -


i trying write multi rewrite function in htacess.

  • change http https
  • remove www
  • remove .html

it should handle cases:
http://www.example.com/about.html
should rewritten as
http s://example.com/about

but of course if there 1 item rewrite should work too:
http://example.com/about
should rewritten as
http s://example.com/about

here code (https , no-www work no-.html commented not work).
please note when rewriting need use rewrited url , not user typed address bar otherwise rule overwrite change rule did.

rewriteengine on  #strip www rewritecond %{http_host} ^www\.(.*)$ [nc] rewriterule ^(.*)$ http://%1/$1 [l,r=301]  #remove .html if #rewritecond %{request_filename}.html -f #rewriterule ^(([^/]*/)*[^/.]+)$ /$1.html [l]  #switch https rewritecond %{server_port} 80 rewriterule ^(.*)$ https://%{http_host}/$1 [l,r=301]  # if directory or file exists, use directly rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d  # otherwise forward index.php rewriterule . index.php  # disable server signature serversignature off 

you can use:

rewriteengine on  #strip www rewritecond %{http_host} ^www\.(.*)$ [nc] rewriterule ^(.*)$ https://%1/$1 [l,r=301]  #switch https rewritecond %{server_port} 80 rewriterule ^(.*)$ https://%{http_host}/$1 [l,r=301]  #remove .html if rewritecond %{the_request} \s/+(?:index)?(.*?)\.html[\s?] [nc] rewriterule ^ /%1 [r=301,l,ne]  # if directory or file exists, use directly rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d # otherwise forward index.php rewriterule . index.php  # disable server signature serversignature off 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -