gpt4 book ai didi

php - htaccess - 将所有文件重写为 index.php,除了 sitemap.xml

转载 作者:行者123 更新时间:2023-12-04 03:08:44 25 4
gpt4 key购买 nike

我试图将每个 php 文件重定向到 index.php,除了 sitemap.xml。问题是 sitemap.xml 也被重定向到 index.php。
如何将所有 php 文件重定向到 index.php 并将 sitemap.xml 重定向到 sitemap.php ?

重写引擎开启
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\[NC]
重写规则 ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.*)\.php$ index.php [L,QSA]
RewriteRule sitemap.xml sitemap/sitemap.php [L]

最佳答案

你需要一个额外的 RewriteCond 来排除 sitemap.php,否则当 sitemap.php 被请求时它会满足两个条件 !-d-f并将再次被重写为 index.php

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\ [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/(sitemap.php)/
RewriteRule ^/?(.*)\.php$ index.php [L,QSA]
RewriteRule sitemap.xml sitemap/sitemap.php [L]

关于php - htaccess - 将所有文件重写为 index.php,除了 sitemap.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46877000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com