Skip to content

Commit

Permalink
Redirect cleanup (#2378)
Browse files Browse the repository at this point in the history
* Revert "Redirect legacy community page (#2319)"

This reverts commit f88599b.

* move community-landing redirect to nginx

* move remainging RedirectViews to nginx

* match intended recirect from community-landing pr
  • Loading branch information
ewdurbin committed Feb 21, 2024
1 parent a7f830a commit 95304aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
9 changes: 0 additions & 9 deletions blogs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,3 @@ def test_blog_home(self):

latest = BlogEntry.objects.latest()
self.assertEqual(resp.context['latest_entry'], latest)

def test_blog_redirects(self):
"""
Test that when '/blog/' is hit, it redirects '/blogs/'
"""
response = self.client.get('/blog/')
self.assertRedirects(response,
'/blogs/',
status_code=301)
24 changes: 24 additions & 0 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ http {
return 301 https://www.python.org/psf;
}

location ~ ^/community-landing/?(.*)$ {
return 301 https://www.python.org/community/;
}

location /doc/Summary {
return 301 http://legacy.python.org/doc/intros/summary;
}
Expand Down Expand Up @@ -204,6 +208,22 @@ http {
return 301 https://www.python.org/download/windows/;
}

location /download/ {
return 301 https://www.python.org/downloads/;
}

location /download/source/ {
return 301 https://www.python.org/downloads/source/;
}

location /download/mac/ {
return 301 https://www.python.org/downloads/macos/;
}

location /download/windows/ {
return 301 https://www.python.org/downloads/windows/;
}

location /Mirrors.html {
return 301 https://www.python.org/mirrors/;
}
Expand Down Expand Up @@ -292,6 +312,10 @@ http {
return 302 /blogs/;
}

location /blog/ {
return 301 https://python.org/blogs/;
}

location /static/ {
alias /app/static-root/;
add_header Cache-Control "max-age=604800, public"; # 604800 is 7 days
Expand Down
10 changes: 1 addition & 9 deletions pydotorg/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
from django.urls import path, re_path
from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.base import TemplateView
from django.conf import settings

from cms.views import custom_404
Expand All @@ -24,18 +24,11 @@
# python section landing pages
path('about/', TemplateView.as_view(template_name="python/about.html"), name='about'),

# Redirect old download links to new downloads pages
path('download/', RedirectView.as_view(url='https://www.python.org/downloads/', permanent=True)),
path('download/source/', RedirectView.as_view(url='https://www.python.org/downloads/source/', permanent=True)),
path('download/mac/', RedirectView.as_view(url='https://www.python.org/downloads/macos/', permanent=True)),
path('download/windows/', RedirectView.as_view(url='https://www.python.org/downloads/windows/', permanent=True)),

# duplicated downloads to getit to bypass China's firewall. See
# https://github.com/python/pythondotorg/issues/427 for more info.
path('getit/', include('downloads.urls', namespace='getit')),
path('downloads/', include('downloads.urls', namespace='download')),
path('doc/', views.DocumentationIndexView.as_view(), name='documentation'),
path('blog/', RedirectView.as_view(url='/blogs/', permanent=True)),
path('blogs/', include('blogs.urls')),
path('inner/', TemplateView.as_view(template_name="python/inner.html"), name='inner'),

Expand All @@ -54,7 +47,6 @@
name='account_change_password'),
path('accounts/', include('allauth.urls')),
path('box/', include('boxes.urls')),
re_path(r'^community-landing(/.*)?$', RedirectView.as_view(url='/community/', permanent=True)),
path('community/', include('community.urls', namespace='community')),
path('community/microbit/', TemplateView.as_view(template_name="community/microbit.html"), name='microbit'),
path('events/', include('events.urls', namespace='events')),
Expand Down

0 comments on commit 95304aa

Please sign in to comment.