Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I redirect /about_us.htm to /about in nginx? Migrating old site to a WordPress setup and none of the old PageRanked URLs work.

I'm trying rewrite ^/about_us.htm /about last; but it's not working.

Thanks!

# site config:
server {

        listen 80;
        server_name www.mysite.com mysite.com;
        root /home/mysite/www/public/;

        if ($http_host != "mysite.com") {
                rewrite ^ http://mysite.com$request_uri? permanent;
        }

        rewrite ^/about_us.htm$ /about last;
        rewrite ^/our_team.html$ /management-team last;

        access_log /home/mysite/www/logs/access.log;
        error_log /home/mysite/www/logs/error.log;

        index index.php index.html index.htm;

        include global/restrictions.conf;

        # Additional rules go here.

        # Only include one of the files below.
        include global/wordpress.conf;

}

wordpress.conf:

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
        try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
        # Zero-day exploit defense.
        # http://forum.nginx.org/read.php?2,88845,page=3
        # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won't get hacked.
        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#       fastcgi_intercept_errors on;
        fastcgi_pass php;
}
share|improve this question
    
Can you show your nginx config for that server? –  cjc Mar 2 '12 at 12:26
1  
Sure, posted. .. –  onemanarmy Mar 2 '12 at 13:05
    
can it be about_us.html instead of htm? –  ustun Mar 2 '12 at 13:28
    
It needs to be .htm. Whoever developed the old version of the site used an inconsistent naming convention. Some pages are .htm, others are .html. Now, there are no extensions in WordPress. I used a WordPress plugin to successfully redirect the pages, but am still curious why my nginx rules are ignored. –  onemanarmy Mar 2 '12 at 23:25
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.