Destoon7.0网站搬家Apache转换Nginx伪静态遇到的问题备忘录
2023年2月7日晚,几个Destoon网站在Windows 2008 Server 上由于Apache占用资源太多,网站打开不理想,所以重装了CentOS7系统,使用轻量级的nginx+宝塔,由于在Windows系统中修改过.htaccess中的伪静态规则,搬家到CenOS系统上,网站详情页都打不开,全部404。
第一个网站的.htaccess 伪静态规则使用宝塔的Apache转Nginx后,仍然是404,测试Destoon里的.htaccess、以及网上许多nginx的规则还是不行。第二天起床后查看伪静态规则,问题出在以下规则上:
RewriteRule ^(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$ $1/show.php?itemid=$2&page=$4 #这是destoon的
RewriteRule ^(.*)/ ([0-9]+)([\-])?([0-9]+)?\.html$ $1/show.php?itemid=$2&page=$4 #这是之前Apache的,就是这行出的问题。
rewrite ^/(.*)/show-([0-9]+)([-])?([0-9]+)?.html$ /$1/show.php?itemid=$2&page=$4 last; #这是这个https://www.laike.net/article-15-71774-0.html 网站的,已测此伪静态规则在刚刚安装的destoon程序中可用。
将该网站上的nginx伪静态规则去除”show-“这几个字符后,网页可以正常打开了。
第二个网站,记得多年前弄伪静态规则的时候,第二个和第一个的伪静态规则是一模一样的,可能记不清楚了,于是将两个伪静态规则对照查看,确实一模一样,将第一个正常的贴入第二个网站,内页却打不开,又404了。查看网址,两个网站的网址并不一样。
第一个是这样的:http://www.***.com/info/12345.html
第二个是这样的:http://www.***.com/view-12345.html
于是将第二个网站之前Apache的伪静态规则贴入宝塔的Apache转Nginx,将转换后的规则放入第二个网站,网页正常打开了。
第三个DT,.htaccess伪静态规则是DT默认的,没有修改过。完整贴入上面所说某网站的nginx规则,网页正常打开。
娜莎兰-李凌云-记之以备忘。归纳:不同问题要不同对待!
附:
以下是上面所说某网站的nginx规则,该规则在初始安装DT后一切正常。
rewrite ^/(.*).(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /404.php last;
rewrite ^/(.*)/file/(.*).php(.*)$ /404.php last;
rewrite ^/(.*)-htm-(.*)$ /$1.php?$2 last;
rewrite ^/(.*)/show-([0-9]+)([-])?([0-9]+)?.html$ /$1/show.php?itemid=$2&page=$4 last;
rewrite ^/(.*)/list-([0-9]+)([-])?([0-9]+)?.html$ /$1/list.php?catid=$2&page=$4 last;
rewrite ^/(.*)/show/([0-9]+)/([0-9]+)?([/])?$ /$1/show.php?itemid=$2&page=$3 last;
rewrite ^/(.*)/list/([0-9]+)/([0-9]+)?([/])?$ /$1/list.php?catid=$2&page=$3 last;
rewrite ^/(.*)/([A-za-z0-9_-]+)-c([0-9]+)-([0-9]+).html$ /$1/list.php?catid=$3&page=$4 last;
rewrite ^(.*)/([a-z]+)/(.*).shtml$ $1/$2/index.php?rewrite=$3 last;
rewrite ^/(com)/([a-z0-9_-]+)/([a-z]+)/(.*).html$ /index.php?homepage=$2&file=$3&rewrite=$4 last;
rewrite ^/(com)/([a-z0-9_-]+)/([a-z]+)([/])?$ /index.php?homepage=$2&file=$3 last;
rewrite ^/(com)/([a-z0-9_-]+)([/])?$ /index.php?homepage=$2 last;
以下是国外某网站Apache转Nginx转换后的结果,经测试,这个规则才是正确的,第一个网站使用以上红色代码后,虽然网页能打开,但后台文本编辑器不能上传图片,随html粘贴的图片显示图片缺失,帖子缩略图图片也不能正确显示。以下规则使用正常,暂时没有检测到bug:
# nginx configuration by winginx.com error_page 404 /404.php; location / { rewrite ^/(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /404.php; rewrite ^/(.*)-htm-(.*)$ /$1.php?$2; rewrite ^/(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$ /$1/show.php?itemid=$2&page=$4; rewrite ^/(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html$ /$1/list.php?catid=$2&page=$4; rewrite ^/(.*)/([A-za-z0-9_\-]+)-c([0-9]+)-([0-9]+)\.html$ /$1/list.php?catid=$3&catdir=$2&page=$4; rewrite ^/(.*)/show/([0-9]+)/([0-9]+)?([/])?$ /$1/show.php?itemid=$2&page=$3; rewrite ^/(.*)/list/([0-9]+)/([0-9]+)?([/])?$ /$1/list.php?catid=$2&page=$3; rewrite ^/(.*)/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /$1/index.php?moduleid=$2&catid=$3&itemid=$4&page=$5; rewrite ^/(.*)/([a-z]+)/(.*)\.shtml$ /$1/$2/index.php?rewrite=$3; } location /admin { rewrite ^(.*)$ /404.php; } location /cache { rewrite ^(.*)$ /404.php; } location /file { rewrite ^(.*)$ /404.php; } location /include { rewrite ^(.*)$ /404.php; } location /lang { rewrite ^(.*)$ /404.php; } location /module { rewrite ^(.*)$ /404.php; } location /skin { rewrite ^(.*)$ /404.php; } location /template { rewrite ^(.*)$ /404.php; } location /com { rewrite ^/(com)/([a-z0-9_\-]+)/([a-z]+)/(.*)\.html$ /index.php?homepage=$2&file=$3&rewrite=$4; rewrite ^/(com)/([a-z0-9_\-]+)/([a-z]+)([/])?$ /index.php?homepage=$2&file=$3; rewrite ^/(com)/([a-z0-9_\-]+)([/])?$ /index.php?homepage=$2; }