Answer the question
In order to leave comments, you need to log in
How to change uri to a new one (to be processed by another location) without a redirect?
Moved the old project to the new cms ( open-real-estate ) written in yii.
There is a need to redirect old urls to new ones, but without redirecting the client.
Here are my 2 solutions:
1.
rewrite ^/cg-([0-9]*)[/]*$ /property/cg-$1 permanent;
location ~ ^/cg-([0-9]*)[/]*$ {
try_files $uri /property/cg-$1;
}
server {
listen 80;
server_name localhost;
charset utf-8;
error_log /home/costa/logs/nginx.log;
root /home/costa/html;
index index.php;
# rewrite ^/cg-([0-9]*)[/]*$ /property/cg-$1 permanent;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/cg-([0-9]*)[/]*$ {
try_files $uri /property/cg-$1;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
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;
}
}
Answer the question
In order to leave comments, you need to log in
I suggest to combine:
location ~ ^/cg-([0-9]*)[/]*$ {
rewrite ^/cg-([0-9]*)[/]*$ /property/cg-$1 break;
try_files $uri @php;
}
location @php {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
See the documentation for nginx/rewrite
If the "to" rule does not include the scheme (http:// or https://) , then you can do an internal redirect.
Files
/old/path/index.html with the text "Old";
/new/path/index.html with the text "New";
Try this rule
location ~ /old/path {
rewrite /old/path(.*) /new/path$1 break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question