Closed ghost closed 2 years ago
I don't know if there is a way to rewrite the URLs to remove the .html
extension. You may need to look into your webserver's configuration if that is possible, but I think mdBook's linkifier will make that difficult. I believe this is mostly a duplicate of #1563, so closing in favor of that.
I had similar questions. I guess we could do something like this in .htaccess
(Apache):
RewriteEngine On
# If the request ends with a /, try to find the corresponding .html file
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
RewriteRule ^(.*[^/])/$ $1.html [L]
This rule works as follows:
RewriteCond
checks if the .html
file corresponding to the directory-like URL exists.RewriteRule
will rewrite the request to the .html
file.For example, with this rule:
https://example.com/book/appendix/author/
would serve the content of https://example.com/book/appendix/author.html
.https://example.com/book/appendix/feedback/
would serve the content of https://example.com/book/appendix/feedback.html
.As for performance concerns:
But I'd rather do something like this https://github.com/rust-lang/mdBook/issues/1563, I'm not sure if that would be a long-term solution 🤔.
Is there any way to implement a
.htacces
file that can be used to negate the.html
proceeding after the URL? I assumed that the 404 was handled by a.htaccess
file but that seems to be handled through something else (presumably JS). Which leads back to my question; is there a way to remove the.html
?