无法访问放置在根文件夹中的 yii2 项目中的站点地图

     2023-02-24     148

关键词:

【中文标题】无法访问放置在根文件夹中的 yii2 项目中的站点地图【英文标题】:Cannot access sitemap in yii2 project placed in root folder 【发布时间】:2022-01-16 19:13:43 【问题描述】:

我为我的 yii2 项目创建了一个 sitemap.xml。我将它放在根文件夹中,但我似乎无法使用此 URL 访问它:https://www.mywebsite.com/sitemap.xml。我需要将 URL 输入到 Google Search Console。

我到处搜索,但似乎关于 yii2 和站点地图的信息非常少。

放置sitemap.xml 的正确方法是什么?我相信它可以在 htaccess 文件中修复,但我不知道如何。

Options +FollowSymlinks
RewriteEngine On

# deal with backend first
RewriteCond %REQUEST_URI /(backend)
RewriteRule ^backend/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^backend/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^backend/font/(.*)$ backend/web/font/$1 [L]
RewriteRule ^backend/plugins/(.*)$ backend/web/plugins/$1 [L]
RewriteRule ^backend/images/(.*)$ backend/web/images/$1 [L]
RewriteRule ^backend/img/(.*)$ backend/web/img/$1 [L]
RewriteRule ^backend/js/(.*)$ backend/web/js/$1 [L]
RewriteRule ^backend/app-assets/(.*)$ backend/web/app-assets/$1 [L]

RewriteCond %REQUEST_URI !/backend/web/(assets|css|font|plugins|images|img|js|app-assets)/
RewriteCond %REQUEST_URI /(backend)
RewriteRule ^.*$ backend/web/index.php [L]


RewriteCond %REQUEST_URI /(assets|css|js|img|font|uploads)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^img/(.*)$ frontend/web/img/$1 [L]
#RewriteRule ^uploads/(.*)$ frontend/web/uploads/$1 [L]
RewriteRule ^uploads/(.*)$ uploads/$1 [L]

RewriteCond %REQUEST_URI !/(frontend|backend)/web/(assets|css|js|img|images|font|fonts|uploads|plugins|app-assets)/
RewriteCond %REQUEST_URI !index.php
RewriteCond %REQUEST_FILENAME !-f [OR]
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^.*$ frontend/web/index.php

<IfModule mod_expires.c>
  ExpiresActive On

 # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/webm "access plus 1 year"
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # Fonts
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

试图解决这个问题已经数周没有成功。请帮忙。

【问题讨论】:

“我似乎无法访问它” - 会发生什么?你得到什么回应? (也许是您框架中的 404?) 【参考方案1】:
RewriteCond %REQUEST_FILENAME !-f [OR]
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^.*$ frontend/web/index.php

您需要在上述条件下删除OR 标志,否则此表达式(不是文件或不是目录)将始终为真并请求sitemap.xml(或任何其他尚未在上述条件中排除的静态资源)将被路由到frontend/web/index.php

这两个否定条件应该是隐式AND'd,而不是OR'd。

【讨论】:

【参考方案2】:

我可以很好地使用一些“动态”: 你可以制作一个像frontend\controllers\SitemapController 这样的新控制器,并在“FORMAT_RAW”中提供它。

另外 - 'sitemap.xml' => 'sitemap/index',在 urlManager 中。 (控制器/视图)

【讨论】:

【参考方案3】:

感谢您的回答。不过解决方法其实很简单,我刚刚才发现。

我将我的 sitemap.xml 文件移动到 frontend/web 文件夹,它可以工作。

【讨论】:

无法访问 virtualenv 中的系统站点包

】无法访问virtualenv中的系统站点包【英文标题】:Unabletoaccesssystemsitepackagesinsidevirtualenv【发布时间】:2019-06-2408:40:02【问题描述】:全球蟒蛇whichpython3.6给予/usr/bin/python3全局python3内部importtensorrt工作正常,但创建虚拟环境mkvirtua... 查看详情

XAMPP - 无法访问 htdocs 中的项目

...sed【发布时间】:2014-09-0514:49:41【问题描述】:我的htdocs文件夹中有许多不使用任何PHP框架的项目由于我安装了Laravel(在内部文件夹中),我无法从浏览器访问它们,它总是说:“哎呀,好像出了点问题。”我怀疑问题出在Larav... 查看详情

Yii 包访问 url 中的文件

】Yii包访问url中的文件【英文标题】:Yiipackageaccessthefilesinurl【发布时间】:2016-08-1010:17:00【问题描述】:我已经安装了本地服务器的YII2并且我还安装了一个包。https://github.com/dektrium/yii2-user现在一切都准备好了,我想在url中访... 查看详情

我的用户站点中的文件夹是不是与项目站点冲突?

】我的用户站点中的文件夹是不是与项目站点冲突?【英文标题】:Doesafolderinmyusersiteconflictwithaprojectsite?我的用户站点中的文件夹是否与项目站点冲突?【发布时间】:2014-10-1307:39:21【问题描述】:GitHubPages允许每个用户拥有一... 查看详情

无法从 ASP.Net 网站项目中的代码访问 App_Code 中的类

...样的问题,我使用DotNetNuke创建了新的网站项目,在App_Code文件夹中添加了类,现在当我尝试从后 查看详情

无法访问 Vue 文件脚本标签中的 CSS 变量

】无法访问Vue文件脚本标签中的CSS变量【英文标题】:Can\'taccessCSSvariablesinscripttagofVuefile【发布时间】:2020-12-0207:40:39【问题描述】:问题我正在尝试从.vue文件访问在SCSS文件中定义的变量。该项目正在使用vue-cli。根据Vue\'sdocs:... 查看详情

无法使用 Apache 服务器访问子目录中的文件

】无法使用Apache服务器访问子目录中的文件【英文标题】:Can\'taccessfilesinasubdirectoryusingApacheserver【发布时间】:2012-01-1801:20:27【问题描述】:我的Windows7机器上安装了Apache2.2.21服务器。我的站点已启动,/scripts子目录中的脚本正... 查看详情

jQuery 访问站点中的 DOM

】jQuery访问站点中的DOM【英文标题】:jQuerytoaccessDOMinasite【发布时间】:2014-10-2818:35:15【问题描述】:我正在尝试从site中抓取表格中的各种元素,以自学使用node.js、cheerio和request进行抓取我在获取表格中的项目时遇到问题,基... 查看详情

无法访问 MoPub iOS SDK 中的头文件

...。【问题讨论】:【参考方案1】:您没有正确导入MoPubSDK文件夹。删除它(导航面板中的蓝色文件夹)并再次导入文件夹 查看详情

.htaccess 文件中的大量条目会减慢站点访问速度吗?

】.htaccess文件中的大量条目会减慢站点访问速度吗?【英文标题】:Willlotsofentriesin.htaccessfileslowsiteaccessdown?【发布时间】:2012-03-1520:17:55【问题描述】:我计划使用(301.htaccess)重定向大约100个,并且想知道这是否会降低性能或有... 查看详情

如何打开放置在iframe html中直接访问阻止目录中的pdf文件

】如何打开放置在iframehtml中直接访问阻止目录中的pdf文件【英文标题】:howtoopenpdffilethatisplacedindirectaccessblockeddirectoryiniframehtml【发布时间】:2021-09-0203:23:35【问题描述】:我所做的是我对包含pdf的目录之一设置了直接访问限制... 查看详情

无法从静态库访问快速文件到应用程序目标

】无法从静态库访问快速文件到应用程序目标【英文标题】:Unabletoaccessswiftfilefromstaticlibrarytoapplicationtarget【发布时间】:2018-01-2417:13:17【问题描述】:我的工作区包含子项目,其中一个子项目生成静态库,其中包含ObjC和链接到... 查看详情

如果配置文件中的多个站点之一无法解析,nginx 将无法启动。 “在上游找不到主机”

】如果配置文件中的多个站点之一无法解析,nginx将无法启动。“在上游找不到主机”【英文标题】:nginxfailstostartifoneofthemanysitesinitsconfigfilenotresolving."hostnotfoundinupstream"【发布时间】:2021-10-2916:22:52【问题描述】:如果... 查看详情

无法访问 Flash as3 中的阶段

】无法访问Flashas3中的阶段【英文标题】:can\'taccessstageinflashas3【发布时间】:2012-12-0913:38:27【问题描述】:我刚切换到AS3我在从MovieClips访问时间线变量时遇到问题。在AS2中我们曾经做_root.myvar,我检查了引用,我发现_root现在... 查看详情

如何从我的 servlet 类访问放置在 /tmp 文件夹中的 sqlite db 文件?

】如何从我的servlet类访问放置在/tmp文件夹中的sqlitedb文件?【英文标题】:Howtoaccessmysqlitedbfileplacedin/tmpfolderfrommyservletclass?【发布时间】:2014-01-2811:44:48【问题描述】:我正在编写一个JSP-Servlet应用程序,我需要在其中写入和读... 查看详情

站点错误:访问 php 项目

】站点错误:访问php项目【英文标题】:Siteerror:Accessingphpproject【发布时间】:2014-07-0520:07:40【问题描述】:我在访问xampp页面根目录中的任何php页面(默认除外)时遇到以下错误,并且我在项目目录中包含了以下所需的dll,但... 查看详情

无法访问 Razor 页面中的模型项目

】无法访问Razor页面中的模型项目【英文标题】:Can\'taccessModelitemsinRazorPage【发布时间】:2022-01-1018:36:14【问题描述】:希望尝试将Dapper作为EFCore的可能替代品。我有一个简单的型号publicclassCDItemFormModelpublicintIdget;set;publicstringItem... 查看详情

我应该在我的 winform c# 应用程序中实现啥形式的身份验证才能访问 SharePoint 站点中的文件夹?

...程序中实现啥形式的身份验证才能访问SharePoint站点中的文件夹?【英文标题】:whatformofauthenticationshouldiimplementinmywinformc#applicationtogainaccesstofoldersinaSharePointsite?我应该在我的winformc#应用程序中实现什么形式的身份验证才能访问Shar... 查看详情