Using apache .htaccess to rewrite "/" as ".html" -
to give quick example of i'm after, want:
example.com/folder/about/   will show me page located at:
example.com/folder/about.html currently, .htaccess file looks this:
rewriteengine on rewritebase / rewritecond %{request_filename} !-f rewritecond %{request_filename}.html -f rewriterule ^folder/(.*)$ folder/$1\.html [nc,r=301,l] which works when go to:
example.com/folder/about but not when go to:
example.com/folder/about/ which tries load:
example.com/folder/about.html/ which not file or directory.
you can use %{request_filename} variable second time, capturing file name:
rewriteengine on rewritebase /  rewritecond %{request_filename} !-f rewritecond %{request_filename}.html -f #new line rewritecond %{request_filename}.html .*/(.*)/? rewriterule ^folder/ folder/%1 [nc,r=301,l] update
put before previous block
rewritecond %{request_filename} !-f rewritecond %{request_filename}.html -f rewriterule ^folder/(.*)/ folder/$1 [nc,r=301,l] 
Comments
Post a Comment