WebFaction
Community site: login faq

I have a django app and want to make 301 permanent redirects from old url structure to a new one within the same domain - e.g. http://domain.com/blog/1/long-slug to http://domain.com/blog/long-slug.

I put the following rule within a Location directive within httpd.conf:

Location "/blog/"
RewriteCond %{REQUEST_URI} ^domain.com/blog/$
RewriteRule ^[0-9]+/([A-Za-z0-9-]+)/?$ http://domain.com/blog/$1 [R=301,NC]
Location

Unfortunately it doesn't work. Any tips would be highly appreciated. Thank you!

P.S. <> around Location directive didn't appear in this preview so I intentionally omitted it

asked 05 Mar '15, 11:51

jakub_l
2528
accept rate: 0%


I see a couple of problems here:

  • %{REQUEST_URI} will never include the domain, so take that out of the RewriteCond
  • Your RewriteCond condition and your RewriteRule` pattern are mutually exclusive - so if you meet the condition, the rewrite pattern will never be met.

I think something like this might work, or at least get you going in the right direction:

RewriteCond %{REQUEST_URI} ^/blog/[0-9]+
RewriteRule ^/blog/[0-9]+/([A-Za-z0-9-]+)$ http://domain.com/blog/$1 [R=301,NC]

If you need help troubleshooting, you can use RewriteLog and RewriteLogLevel in your httpd.conf to get some details about what is matching and what isn't.

Hope that helps!

permanent link

answered 05 Mar '15, 19:22

seanf
12.2k41836
accept rate: 37%

great, thank you Sean. I also forget to add RewriteEngine On directive.

(06 Mar '15, 08:29) jakub_l
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×76
×28
×9

question asked: 05 Mar '15, 11:51

question was seen: 2,184 times

last updated: 06 Mar '15, 08:29

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM