---
slug: "DjangoRedirectViewをURLsでインラインで使って、URLパスを保持したままリダイレクトする"
title: "Using Django RedirectView Inline in URLs to Redirect While Preserving URL Path"
description: "\n\nI want to redirect people who access /url-path-before/feature/hoge/ to /url-path-after/feature/hoge/."
url: "https://www.ytyng.com/en/blog/DjangoRedirectViewをURLsでインラインで使って、URLパスを保持したままリダイレクトする"
publish_date: "2015-12-22T09:57:19Z"
created: "2015-12-22T09:57:19Z"
updated: "2026-02-27T10:43:05.587Z"
categories: ["Django"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/6be8b3ca2e834d84802fdb4e4bf9bbd0.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# Using Django RedirectView Inline in URLs to Redirect While Preserving URL Path

<div class="document">

<p>I want to redirect people who access /url-path-before/feature/hoge/ to /url-path-after/feature/hoge/.</p>
<p>Using URLs, you can do it like this:</p>
<pre class="literal-block">url(r'^url-path-before/(?P&lt;path&gt;.*)',
    RedirectView.as_view(url="/url-path-after/%(path)s", permanent=False),
    name="after"),
</pre>
<p>This will enable the redirection.</p>
<p>If you set permanent=False, it will be a 302 redirect.</p>
<p>If you don't specify, permanent=True will be used, resulting in a 301 redirect.</p>
<p>Since 301 redirects can be cached by the browser and cause inconvenience, it might be a good idea to start with permanent=False for testing. If there are no issues with the behavior, you can remove it later.</p>
</div>
