我在简单的 SEO 友好重定向方面遇到了问题。网页已更改,我想将旧 uri 重定向到新 uri。例如,我想将 /contact 重定向到 /contact.html
我试过了
location = /contact {
rewrite ^ /contact.html permanent;
}
但它似乎不起作用,Nginx 继续将请求传递给 Zend 前端控制器(PHP)。
这是我当前的配置(没有重写)
server {
listen *:80;
server_name www.domain1.com domain1.com domain2.com www.domain2.com;
error_log /var/log/nginx/domain1.error.log notice;
root /home/domain1/www/public/;
client_max_body_size 22M;
#domain redirect
if ($host != 'www.domain1.com' ) {
rewrite ^/(.*)$ http://www.domain1.com/$1 permanent;
}
location / {
index index.php;
}
# html cache static content
location ~* \.(js|css|rdf|xml|ico|txt|gif|jpg|png|jpeg|swf|eot|ttf|woff)$ {
expires 30d;
}
rewrite /path1/(\w*)/\w*\.(\w*) /path2/$1.$2;
#Zend front controller
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9200;
fastcgi_param SCRIPT_FILENAME /home/domain1/www/public$fastcgi_script_name;
fastcgi_param APPLICATION_ENV production;
include /etc/nginx/fastcgi_params;
}
}
答案1
我会做得更简单,把它放在你的/位置的顶部
location / {
rewrite ^/contact$ /contact.html permanent;
....
....
}