从aws ec2更改为aws s3后出现404错误,媒体文件URL更改

时间:2019-03-25 10:13:29

标签: django amazon-s3

该应用程序位于aws ec2中,所有媒体文件的url均采用https://example.com/media/k1/literacy/Big_Ben.mp3格式,许多人都在使用该url,但是将其更改为aws s3之后,其URL路径已更改为https://example.s3.amazonaws.com/prod/media/k1/literacy/Big_Ben.mp3显示通过旧网址访问时找不到404文件。

->单击旧url后如何将旧url重定向为新url格式。

->我们不能忽略,因为许多人都在使用旧网址。

url(r“ ^ media /”,``,redirect_to,{'url': 'https://example.s3.amazonaws.com/prod/media/Grade_1/Maths/BachGavotteShort.mp3'})

import debug_toolbar
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path  # For django versions from 2.0 and up
from rest_framework_jwt.views import obtain_jwt_token

from accounts import views
from activity_app.views import authenticate_user
from django.views.generic.simple import redirect_to

urlpatterns = [
    url(r"^admin/doc/", include("django.contrib.admindocs.urls")),
    url(r"^admin/", admin.site.urls),
    url(r"^media/", '', redirect_to, {'url': 
'https://example.s3.amazonaws.com/prod/media/Grade_1/Maths/BachGavotteShort.mp3'}),

    # url(r"^career_app/", include("career_app.urls")),
    path("__debug__/", include(debug_toolbar.urls)),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

当某人使用旧的ec2网址时,应重定向到新的aws s3 urland,以显示媒体文件。

0 个答案:

没有答案