normalize_url | Normalizing URLs like a boss | REST library
kandi X-RAY | normalize_url Summary
kandi X-RAY | normalize_url Summary
Normalizing URLs like a boss
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of normalize_url
normalize_url Key Features
normalize_url Examples and Code Snippets
Community Discussions
Trending Discussions on normalize_url
QUESTION
At Now when url is opened (without a slash - example.com/blog
), a slash is automatically added at the end (there are 301
redirects). The question is, can I somehow do it so that the check first goes to see if the page exists (without a slash - example.com/blog
). If so, open it. If not, then check whether the page exists with a slash (only without 301
- example.com/blog/
). If so, then redirect 301
, and if not, then throw 404
.
Now just if there is no page (example.com/blog
), then a slash is added to the end first (example.com/blog/
), 301
redirects go and only then a 404
error is thrown. In this case, the 404
error must be thrown immediately, without a 301
redirect.
The dispatch
was rewritten as follows.
ANSWER
Answered 2019-Aug-23 at 09:56First make sure you set APPEND_SLASH
to False
in your settings.py. This will disable the automatic 301 redirects to the URLs with slash.
Then use resolve()
to check if the URL with slash exists before redirecting. Do this in a Middleware class where you handle the case that the response
status code is 404.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install normalize_url
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page