我正在将我的网站迁移到另一个平台,但在完成新网站的所有页面开发时,我需要我的用户在两个平台之间进行导航。
所以我需要对包含1个单词的所有URL进行301redirect,但不包含其他单词:
例:
我需要redirect包含单词“www2.misite.com/travel(.*)”的所有url,但不包含“预订”和“酒店”等字样。
我的服务器是Nginx,我不知道这是用正则expression式还是用nginx语句完成的。
非常感谢你。
我能够通过以下方式解决我的问题:
location ~ /travel(.*)+/(.*)$ { if ($uri !~ "^(.*)/(reservation|hotel|faq)(.*)"){ return 301 https://www.misite.com$request_uri; } autoindex on; root /usr/share/nginx/html/sites/; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; }
谢谢。
尝试正确的expression方式,对于不希望转发的两个单词进行负面预测。 你可以在if条件或重写规则中做到这一点。
我试试
location ~ /travel(.*)+/(.*)$ { if ($request_uri !~ "^/(reservation|hotel|faq)/\w+$"){ return 301 https://www.misite.com/$1; } }
但不适合内部条件。 🙁