[英]redirect everything under one path to another domain - nginx
我有重寫/重定向網址的問題。
我有網站website.com/news ..其中/ news是所有文章。
我做了新網站articles.website.com,我想重定向/ news下的所有鏈接重定向到articles.website.com。
因此在示例中:
在nginx上可能會在website.com/news/awesome-article上重定向/重寫article.website.com/awesome-article嗎? 謝謝。
我用了
location ~ ^/news/(.*) {
return 301 http://www.articles.website.com/$1;
}
但是它仍然在articles.website.com/news/awesome-article ..上的新URL重定向上,但是我希望它沒有/ news。
我要重定向的網站的虛擬主機(website.com)
server {
listen 80; ## listen for ipv4; this line is default and implied
root /var/www/vhosts/website.com;
index index.html index.htm index.php;
error_log /var/log/nginx/website.com.error.log;
access_log /var/log/nginx/website.com.access.log;
server_name dev.website.com website.com www.website.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
# location = /news {
#return 301 http://articles.website.com$1;
#}
# location = /news/ {
# return 301 http://articles.website.com/$1;
#}
# location = /news/wp-login.php {
# return 301 http://articles.website.com/wp-login.php$1;
#}
location ~ ^/news/(.*) {
return 301 http://articles.website.com/??$1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
很抱歉打擾。 我不知道為什么,但是nginx不想接受重定向。 一夜之后,我仔細檢查了那個規則,然后就開始了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.