Gaming, Linux, Programming by day. Atheism and tolerance by night. Sci-Fi television all hours of the day.
My company uses Wordpress; at someone’s recommendation, I tried using the Redirection Plugin when trying to migrate our installs to nginx-powered servers. However, that specific plugin completely broke our site on Nginx. I received absolutely no support from the developers on what was going wrong, and almost no support from the WordPress community who had both Nginx and this plugin working.
Because our company has gone through many mergers and site designs over the past decade, we have a ton of 301 redirects in place.
So, my only option was to “manually” do these conversions.
For those who need to know the actual conversion recipe:
in htaccess: Redirect 301 /from/url /to/url in Nginx: rewrite ^/from/url /to/url permanent;
Rather than do all of these manually, I used trusty VIM to make this conversion quickly from a copy of the htaccess file.
cp .htaccess nginx-redirects
[ESC] #make sure you're not in insertion mode [CTRL+V] #enter visual block mode G #go to the bottom of the document $ #extend to the end of each line
permanent;keyword to the end of each line:
A permanent; #make sure there is a space before the word! [ESC] #leaves visual block mode an applies the changes
%s/Redirect 301 /rewrite ^/gIt’s important to note the spacing here. Below, to make sure we’re all on the same page, I’ve replaced spaces with
+signs — don’t actually use them in your VIM command:
location /block of your nginx config for your site, add
Bam. Done. The only thing to remember is that if you add more, you must reload your nginx settings before they will take effect: