您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
OpenCart 如何开启和设置网站伪静态 (seo rewrite)?
发布时间:2024-10-11 11:33:12编辑:雪饮阅读()
-
首先我们来解决一个问题
关于opencart自建站, 后台弹窗提醒
It is very imporant that you move the storage directory outside of the web dirtory(e.g.public_htmal,www or htdocs)
Important Security Notification
这里我是使用了Automatically Move方式右下角的Move的
但是接下来就报错如:
Warning: fopen(/www/wwwroot/storage/logs/error.log): failed to open stream: No such file or directory in /www/wwwroot/www.opencart3039.com/system/library/log.php on line 22
Warning: fopen(/www/wwwroot/storage/logs/error.log): failed to open stream: No such file or directory in /www/wwwroot/www.opencart3039.com/system/library/log.php on line 22
Warning: fwrite() expects parameter 1 to be resource, bool given in /www/wwwroot/www.opencart3039.com/system/library/log.php on line 31
Fatal error: Uncaught Error: Class 'Twig\Loader\ArrayLoader' not found in /www/wwwroot/www.opencart3039.com/system/library/template/twig.php:31 Stack trace: #0 /www/wwwroot/www.opencart3039.com/system/library/template.php(51): Template\Twig->render() #1 /www/wwwroot/www.opencart3039.com/system/engine/loader.php(125): Template->render() #2 /www/wwwroot/www.opencart3039.com/admin/controller/extension/dashboard/activity.php(118): Loader->view() #3 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerExtensionDashboardActivity->dashboard() #4 /www/wwwroot/www.opencart3039.com/system/engine/loader.php(48): Action->execute() #5 /www/wwwroot/www.opencart3039.com/admin/controller/common/dashboard.php(40): Loader->controller() #6 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerCommonDashboard->index() #7 /www/wwwroot/www.opencart3039.com/admin/controller/startup/router.php(26): Action->execute() #8 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerStartupRouter in /www/wwwroot/www.opencart3039.com/system/library/template/twig.php on line 31
解决宝塔站点列表突然为空
根据上面的提示大概是要有这个路径
/www/wwwroot/storage
那么去宝塔里面去建立这个目录
但发现登录宝塔后让绑定手机号(登录宝塔账号),我好像绑定过,只不过虚拟机迁移过一次吧,可能是从老电脑迁移到新电脑的缘故,还是中间网络配置也有修改的缘故,导致又要绑定一次。
而这次绑定过程出现第一次没有反应,我第二次绑定成功,但进入站点列表发现是空的。
而且不知道怎么操作的就连接拒绝了。
于是我尝试宝塔服务重启
systemctl restart bt
重启后可以再次访问宝塔
我当前宝塔版本是8.0.3,根据论坛的提示切换节点其实没有什么效果,而且也弹窗一个很快的闪烁,没有看出具体是什么。
好像切换节点这里也会导致宝塔连接拒绝,反正中间有几次连接拒绝,具体是在哪些情况,或许这里才出现的,已经记不清楚了。
这次我干脆在右上角点击“更新”
从8.0.3升级到9.2.0就又好了。
站点列表恢复了。
重新解决第一个问题
站点列表恢复后我好像是又试了下直接访问opencart首页,结果又报错,大概是缺少
/www/wwwroot/storage/cache
/www/wwwroot/storage/logs
这两个目录,于是我在宝塔上建立了
再次刷新又剩下错误如:
Fatal error: Uncaught Error: Class 'Twig\Loader\ArrayLoader' not found in /www/wwwroot/www.opencart3039.com/system/library/template/twig.php:31 Stack trace: #0 /www/wwwroot/www.opencart3039.com/system/library/template.php(51): Template\Twig->render() #1 /www/wwwroot/www.opencart3039.com/system/engine/loader.php(125): Template->render() #2 /www/wwwroot/www.opencart3039.com/catalog/controller/common/column_left.php(72): Loader->view() #3 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerCommonColumnLeft->index() #4 /www/wwwroot/www.opencart3039.com/system/engine/loader.php(48): Action->execute() #5 /www/wwwroot/www.opencart3039.com/catalog/controller/common/home.php(12): Loader->controller() #6 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerCommonHome->index() #7 /www/wwwroot/www.opencart3039.com/catalog/controller/startup/router.php(25): Action->execute() #8 /www/wwwroot/www.opencart3039.com/system/engine/action.php(79): ControllerStartupRouter->index() #9 /www/wwwroot/www in /www/wwwroot/www.opencart3039.com/system/library/template/twig.php on line 31
这个时候呢,把/www/wwwroot/www.opencart3039.com/system/storage目录复制并覆盖到
/www/wwwroot/storage目录即可。
可能有权限问题,我是给/www/wwwroot/storage以755权限并所有者www进行递归到子目录授权的。
再次刷新页面就ok了。
那么此时你回到之前的第一个错误的那个后台管理页面刷新后也是ok了。
那么现在回到正题,我们如何设置伪静态?
System=>Settings进入Store List
在这里选择一个Store,一般是Default进行Edit,在 Edit Setting
里面Server=>General里面将Use Seo URLs单选勾选为Yes。
Save后
我们来到站点跟目录如
/www/wwwroot/www.opencart3039.com中找到.htaccess.txt
找到如下部分
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
将这里的
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
复制到
https://www.bt.cn/tools/apache_to_nginx.html
来转换,这是一个将apache规则转换为nginx规则的宝塔提供的在线转换工具。
但我实际测试情况下,发现还是宝塔自己推荐的https://winginx.com/en/htaccess更好用。。。
比如我这里最终转换的结果如:
location ~ .*\.(ico|gif|jpg|jpeg|png|js|css) { } location = /sitemap.xml { rewrite ^(.*)$ /index.php?route=extension/feed/google_sitemap break; } location = /googlebase.xml { rewrite ^(.*)$ /index.php?route=extension/feed/google_base break; } location /system { rewrite ^/system/storage/(.*) /index.php?route=error/not_found break; } location / { if (!-e $request_filename){ rewrite ^/([^?]*) /index.php?_route_=$1 break; } }
然后将最终的转换结果拿到宝塔站点列表中你的opencart所属站点的配置中的伪静态里面直接粘贴到伪静态输入域(这里可以看到也可以在此右上角快速链接到“Apache转nginx”)里面进行保存。
本期词汇
Automatically 无意识地;自动地
Fatal 致命的;导致失败的
Uncaught 没被抓住的,没被捕获的
Cond 电导率;条件数
Twig 小枝,嫩枝
关键字词:opencart,伪静态,seo,rewrite