我的重写/重定向网址有问题。
我有网站website.com/news ..在/ news中所有文章。
我做了新的站点articles.website.com,我想重定向/ news下的所有链接以重定向到articles.website.com。
因此,在示例中:
可以在nginx上对website.com/news/awesome-article进行重定向/重写在articles.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不想接受该重定向。晚上过后,我仔细检查了该规则,它很正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句