我為我的 yii2 專案創建了一個 sitemap.xml。我將它放在根檔案夾中,但似乎無法使用以下 URL 訪問它:https://www.mywebsite.com/sitemap.xml。我需要將其輸入到 Google Search Console 的 URL。
我到處搜索,但似乎有關 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
試圖解決這個問題已經數周了,但沒有成功。請幫忙。
uj5u.com熱心網友回復:
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。
uj5u.com熱心網友回復:
我可以很好地使用一些“動態”:您可以制作一個新的控制器frontend\controllers\SitemapController,并在“FORMAT_RAW”中提供它。
另外 - 'sitemap.xml' => 'sitemap/index',在 urlManager 中。(控制器/視圖)
uj5u.com熱心網友回復:
謝謝你的回答。但解決方案其實很簡單,我剛剛發現。
我將我的 sitemap.xml 檔案移動到 frontend/web 檔案夾并且它作業正常。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389464.html
標籤:php .htaccess yii2 站点地图.xml
