301将django redirect_重定向到多个重定向

时间:2012-07-26 03:30:35

标签: django redirect

我回来寻求建议。我有一个需要SEO帮助的网站,并被要求广告301重定向。这个网站是从我收集的php转换到django。现在我已经获得了大约700个URL的csv,基本上都是

http://www.rhodeislandrow.com/floor-plans/search/?sort=price_desc&floor=---&max_price=1304&min_price=0&csrfmiddlewaretoken=3688d94aa3454e592f016d032a126328&availability=1322629596

我决定在研究之后我需要从django.views.generic.simple导入redirect_来解决这个问题。但是玩这个,它不起作用。任何人都可以帮助我指出要使用的指针吗?我在这里阅读了文档:

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponsePermanentRedirect

这是我的网址:

from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
from django.views.generic.simple import direct_to_template
from django.views.generic.simple import redirect_to
from main.sitemaps import sitemaps
from main.views import *
admin.autodiscover()



urlpatterns = patterns('',
    # Redirects from old site
    (r'^floor-plans/search/$', redirect_to, {'url': 'http://www.rhodeislandrow.com/floor-plans/'}),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^subscribe/$', SubscribeView, name='subscribe'),
    url(r'^vaultware-template/$', VaultwareTemplateView.as_view()),

    url(r'^', include('stateful.urls')),
    url(r'^', include('cms.urls')),
    (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
    (r'^robots.txt$', include('robots.urls')),
)

1 个答案:

答案 0 :(得分:0)

我明白了。因为我的网址没有以/ search /结尾,我需要添加通配符

(r'^floor-plans/search/.*$', redirect_to, {'url': 'http://www.rhodeislandrow.com/floor-plans/'}),

感谢您的回复,我将在未来的项目中使用重定向应用