Need help with Nginx 301 redirects
I have been with Linode since June 2009, on what used to be a 720 (now 1024) and I'm loving it.
Now, I'm trying to build a new web server, on Ubuntu 10.04 LTS, with PHP-FPM (Separate) Installed from Source and Nginx as the web server. I've got everything up and running, thanks to the_guv's brilliant guide
Where I'm struggling and need help with are 301 redirects. I've got Wordpress running, with the proper permalinks, proper www vs non-www but I can't seem to figure out how to do a simple 301 redirect. Coming from using a wordpress plugin and apache .htaccess, I'm lost here.
Example: I'd to redirect
to
Here's what my /usr/local/nginx/sites-available/exampleurl.com file looks like:
server {
listen 80;
server_name exampleurl.com;
rewrite ^/(.*) http://www.exampleurl.com/$1 permanent;
}
server {
listen 80;
server_name www.exampleurl.com;
access_log /home/username/public_html/exampleurl.com/log/access.log;
error_log /home/username/public_html/exampleurl.com/log/error.log;
location / {
root /home/username/public_html/exampleurl.com/public/;
index index.php index.html;
# Wordpress WP Super Cache plugin and permalinks.
include /usr/local/nginx/conf/wordpress_params.super_cache;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/username/public_html/exampleurl.com/public/$fastcgi_script_name;
}
}
Basically, if you could show me an example of what code to insert and where to insert it, using the example above, I would greatly appreciate that. Thanks!
2 Replies
location = /computer-systems/home-theater-pc/1500-2/ {
rewrite ^ /1500-htpc/ permanent;
}
And just repeat for all your preexisting urls.
Syntax might be slightly off. Going off pure memory.
That's exactly what I was looking for and after testing it, I can confirm that it works perfectly.
Thanks a lot for your help and time.
Cheers,
Mathieu