Answer the question
In order to leave comments, you need to log in
How to rewrite from old uri to new without redirect?
Moved an old project to a content management system written in yii ( open-real-estate.info ).
nginx config:
server {
listen 80;
server_name localhost;
charset utf-8;
error_log /home/user/logs/nginx.log;
root /home/user/html;
index index.php;
location = /old-uri {
rewrite /old-uri /service-1 last;
}
location / {
root /home/user/html;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
location = /favicon.ico {
return 204;
}
location ~* \.(jpg|jpeg|gif|ico|png|xml|zip|css|js|html|json|txt|swf|mov)$ {
try_files $uri =404;
expires max;
}
location ~ /\. {
deny all;
log_not_found off;
}
}
location = /old-uri {
rewrite /old-uri /service-1 last;
}
Answer the question
In order to leave comments, you need to log in
You can simply specify permanent instead of last. This is if it is not scary that the link changes with the user. :)
PS: I don't think that separate locations are needed here, I usually put this (rewrite permanent) either in "location /" or even on the "server" level...
You,
location = /old-uri {
rewrite /old-uri /service-1 last;
}
is not needed.
Enough,
rewrite ^/old-uri /service-1 last;
If this does not work, then perhaps when accessing the old-uri, arguments are passed that also need to be passed to / service-1
On a good note, every time the location changes, see the access log to understand what is being passed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question