我有街机游戏网站。我想将我的网址转换为sef。
category : domain.com/index.php?category=mario-games > domain.com/category/mario-games
game details : domain.com/index.php?game=mario-game > domain.com/mario-game.html
featured : domain.com/featured.php > domain.com/featured
pages : domain.com/page.php?id=contact > domain.com/page/contact
搜索完Internet后,我成功地实现了重写规则。但我的旧网址仍然可以访问。我怎样才能将旧网址重定向和重写为新网址?
server {
listen 80;
server_name domain.com;
return 301 http://www.domain.com$request_uri;
}
server {
listen 80;
server_name www.domain.com;
root /usr/share/nginx/domain;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
rewrite ^/(.*).html$ /index.php?game=$1 last;
}
location /category {
rewrite ^/(.+)/$ /$1 permanent;
rewrite ^/category/(.*)$ /index.php?category=$1 last;
}
location /page {
rewrite ^/(.+)/$ /$1 permanent;
rewrite ^/page/(.*)$ /page.php?id=$1 last;
}
location /featured {
rewrite ^/(.+)/$ /$1 permanent;
rewrite ^/(.*) /featured.php last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
expires max; log_not_found off; access_log off;
}
location ~* \.(js|jpg|png|css)$ {
expires 30d;
}
}