.htaccess - Rewriting url rule applied on a folder -
i have url looks : www.mysite.com/directory1/directory2/directory3 .
using htaccess want define rewrite rule able redirect last piece of url in example (directory3) directory3.html
has idea ?
you can use code in document_root/.htaccess
file:
rewriteengine on rewritebase /restapi/ rewritecond %{document_root}/restapi/$1\.html -f [nc] rewriterule ^(.+?)/?$ $1.html [l]
- this rule captures whole uri except last optional slash in back-reference
$1
. - it constructs full filesystem path using
%{document_root}/restapi/$1.html
%{document_root}
internalmod_rewrite
variable representing value of actualdocument_root
path in system. - using
-f
checks whether.html
fils exists. - if condition true routes
.html
file.
Comments
Post a Comment