Redirection from URLs without extension to URLs with `.html` extension

72 views
Skip to first unread message

Denis Bitouzé

unread,
Nov 30, 2023, 5:22:58 AM11/30/23
to sphinx...@googlegroups.com
Hi,

recently, we switched our French LaTeX (more than 1200!) FAQ from
Dokuwiki to Sphinx-doc:

┌────
https://faq.gutenberg-asso.fr/
└────

and it is much much better now :)

But we have a problem with Google SEO. Indeed, the URL of the Dokuwiki
pages were extension-less whereas the URL of the Sphinx pages have the
`.html` extension, e.g.:

┌────
https://faq.gutenberg-asso.fr/3_composition/texte/paragraphes/changer_l_indentation_en_debut_de_paragraphe
└────

vs:

┌────
https://faq.gutenberg-asso.fr/3_composition/texte/paragraphes/changer_l_indentation_en_debut_de_paragraphe.html
└────

And, AFAIU, this penalizes us for the indexation of our pages. Hence my
question: is it possible to make an automatic redirection from the URL
without extension to URL with .html extension?

Thanks.
--
Denis

James Knight

unread,
Nov 30, 2023, 2:36:36 PM11/30/23
to sphinx...@googlegroups.com
Denis,

On Thu, Nov 30, 2023 at 5:22 AM Denis Bitouzé <denis....@gmail.com> wrote:
> [Is] it possible to make an automatic redirection from the URL
> without extension to URL with .html extension?

One approach would be to use the "dirhtml" builder instead of the
"html" builder. This should give a more clean URL pattern when the
documentation is hosted on a site.

Denis Bitouzé

unread,
Dec 2, 2023, 12:09:44 PM12/2/23
to James Knight, sphinx...@googlegroups.com
Hi James,

Le 30/11/23 à 14h35, James Knight a écrit :
I'll have a look, thanks!
--
Denis

Kevin Dunn

unread,
Dec 2, 2023, 4:46:38 PM12/2/23
to sphinx...@googlegroups.com
Hi Denis - have you looked at the `html_file_suffix` and `html_link_suffix` settings options in conf.py? 
These will probably do what you require. 

I use them in my online book (random page: https://learnche.org/pid/data-visualization/box-plots. <- without .html) and my conf.py file is here:  https://github.com/kgdunn/pid-book/blob/master/conf.py 

Regards,
Kevin

--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/87il5gleeo.fsf%40example.com.

Denis Bitouzé

unread,
Dec 3, 2023, 8:54:08 AM12/3/23
to sphinx...@googlegroups.com
Le 02/12/23 à 22h45, Kevin Dunn a écrit :

> Hi Denis - have you looked at the `html_file_suffix` and `html_link_suffix`
> settings options in conf.py?
> These will probably do what you require.
>
> I use them in my online book (random page:
> https://learnche.org/pid/data-visualization/box-plots. <- without .html)
> and my conf.py file is here:
> https://github.com/kgdunn/pid-book/blob/master/conf.py

Many thanks Kevin!

But, well... that does the trick locally, but not online. Random page:

- which is working:
┌────
https://faq.gutenberg-asso.fr/4_domaines_specialises/mathematiques/aligner_des_nombres_sur_la_virgule.html
└────
- which isn't working (the file is downloaded instead of being displayed):
┌────
https://faq.gutenberg-asso.fr/4_domaines_specialises/mathematiques/aligner_des_nombres_sur_la_virgule
└────

The relevant lines of my `conf.py` are here:

┌────
https://gitlab.gutenberg-asso.fr/gutenberg/faq-gut/-/blob/main/source/conf.py?ref_type=heads#L98-L103
└────

Have you a specific setting in your Web server config file?

Regards.
--
Denis

Denis Bitouzé

unread,
Dec 4, 2023, 3:21:19 AM12/4/23
to sphinx...@googlegroups.com
Le 03/12/23 à 14h54, Denis Bitouzé a écrit :

> Have you a specific setting in your Web server config file?

Let's forget about it: we've managed to configure our Nginx Web server
to make the URLs of the pages of our LaTeX Sphinx FAQ extension-free (if
a `.html` were added, there would be an immediate redirection to the
extension-free URL). Here is the Nginx setting we added:

--8<---------------cut here---------------start------------->8---
location / {
if ($request_uri ~ ^/(.*)\.html(\?|$)) {
return 302 /$1;
}
try_files $uri.html $uri $uri/ =404;
}
--8<---------------cut here---------------end--------------->8---

Thanks again.
--
Denis

Denis Bitouzé

unread,
Dec 4, 2023, 4:57:08 AM12/4/23
to sphinx...@googlegroups.com
Le 04/12/23 à 09h21, Denis Bitouzé a écrit :

> Le 03/12/23 à 14h54, Denis Bitouzé a écrit :
>
>> Have you a specific setting in your Web server config file?
>
> Let's forget about it: we've managed to configure our Nginx Web server
> to make the URLs of the pages of our LaTeX Sphinx FAQ extension-free (if
> a `.html` were added, there would be an immediate redirection to the
> extension-free URL). Here is the Nginx setting we added:
>
> location / {
> if ($request_uri ~ ^/(.*)\.html(\?|$)) {
> return 302 /$1;
> }
> try_files $uri.html $uri $uri/ =404;
> }

In fact, we had to revert both the above setting and, in `conf.py`:

┌────
│ html_file_suffix = ""
│ html_link_suffix = ""
└────

because, after some time, though our extension-free files are non empty,
the pages served by the server are empty (we are not sure if it is
related but the .html files are empty).
--
Denis
Reply all
Reply to author
Forward
0 new messages