-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with URL rewriting #4466
Comments
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
This is still relevant today, for the reasons stated earlier. |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Discourse thread: https://discourse.gohugo.io/t/compatibility-with-url-rewriting/10776
I'm using
uglyURLs=true
to generate nice, standard pages with an uncluttered file layout (beautiful, in my opinion), and I'm also using URL rewriting on the web server to achieve pretty URLs. In my opinion, this is a fairly standard web setup. The problem with this is that it completely breaks any URLs that Hugo generates.I would therefore like to request a new feature in Hugo: compatibility with URL rewriting on the server.
I have three ideas for how this could be implemented.
Option 1:
Introduce a new configuration variable (e.g. for
config.toml
) calledrewriteURLs
, withtrue
andfalse
as valid values, andfalse
as the default value.When
rewriteURLs
anduglyURLs
are both set to true, then functions such asref
andrelref
, and params such as.URL
and.Permalink
will always act as ifuglyURLs
isfalse
, even though it isn't.This seems like the simplest solution, but it is also the least flexible as it only supports one specific URL rewriting setup: removing the page's file extension. That might be acceptable though, as this is likely the most common setup anyway.
Option 2:
Introduce a new page front matter variable called
rewrittenURL
, which supports string values.When a page has the
rewrittenURL
param set, then functions such asref
andrelref
, and params such as.URL
and.Permalink
will always use therewrittenURL
value; it overrides whatever URL would normally be used.This approach would be similar to the current
URL
front matter param - the difference being thatrewrittenURL
would have absolutely no effect on the generated file path.This is more flexible than Option 1, as any kind of URL would be supported. However, it's less maintainable for users of Hugo, as they would have to specify the URL on every single page.
Option 3:
Introduce new configuration variables (e.g. for
config.toml
) which support any number of "rewrite rules". These could be directly compatible with the .htaccess rewrite rule syntax, or they could just use a similar syntax. Users would be able to specify custom regular expression rules to rewrite URLs, and Hugo would then use these whenever a URL needs to be displayed.This seems like the ideal solution, as it's very flexible and also very maintainable for the user. However, it's probably also the hardest solution to implement.
Thanks for reading. Do any of these changes seem reasonable to you?
The text was updated successfully, but these errors were encountered: