WebFaction
Community site: login faq

I want to create a few redirects for my django app. So I've created a Static/CGI/PHP app just for redirecting. In it there's an .htaccess file with

# https/domain forwarding
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

This part works, but I also want to redirect

www.mydomain.com/cat/some-category/some-long-slug

==> www.mydomain.com/category/name/some-long-slug`

I've tried a couple of configurations like

# slug redirect
RewriteCond %{REQUEST_URI} /cat/used-cars/?$
RewriteRule /?$ https://www.mydomain.com/category/cars/ [R=301,NC]

or

RewriteCond %{REQUEST_URI} /cat/used-cars/?$
RewriteRule ^cat/used-cars/$ https://www.mydomain.com/category/cars/ [R=301,NC]

also doesn't work. and neither does:

RewriteCond %{REQUEST_URI} ^www.mydomain.com/cat/used-cars/$ 
RewriteRule ^(.*)$ https://www.mydomain.com/category/cars/$1 [R=301,NC]

As you can see I'm a little lost with the 301 htaccess scripting, so any tips would be appreciated. Thank you!

asked 06 Jun '13, 09:32

alphydan
5157
accept rate: 0%

edited 07 Jun '13, 06:42


You can't use a redirect app between the same domain without redirect loops, redirect apps are best for sub-domain -> domain, or HTTP -> HTTPS, betweeen the same app you should put the last rule within a Location directive within httpd.conf. The last line is close to right, to pass URI you use $1, however without testing it in real-time its really hard to say. You should also be using curl to test, since browsers will cache 301s and make testing impossible.

<Location "/cat/used-cars/">
    RewriteCond %{REQUEST_URI} ^www.mydomain.com/cat/used-cars/$ 
    RewriteRule ^(.*)$ https://www.mydomain.com/category/cars/$1 [R=301,NC]    
</Location>
permanent link

answered 06 Jun '13, 17:04

johns
5.3k312
accept rate: 23%

thank you for the curl suggestion, and the separation of httpd.conf and .haccess to avoid loops. However, when I implement your suggestion and curl -I the http://www.mydomain.com/cat/used-cars/ I see: HTTP/1.1 301 Moved Permanently Server: nginx Date: Fri, 07 Jun 2013 11:48:33 GMT Content-Type: text/html; charset=iso-8859-1 Connection: keep-alive Location: https://www.mydomain.com/cat/used-cars/ (so it knows to redirect, but somehow doesn't?)

(07 Jun '13, 06:55) alphydan

@alphydan - I think it will be much easier for us to help you with this if you open a support ticket, so that we can see the actual site and configuration files that you're working with.

(07 Jun '13, 19:06) seanf
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
×33
×9

question asked: 06 Jun '13, 09:32

question was seen: 3,530 times

last updated: 07 Jun '13, 19:06

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