使用.htaccess重定向整个网站,但不包括sitemap.xml和robots.txt



Hey Stack Overflowers。

我使用php、mysql和php路由器概念创建了一个博客。

所有请求都会转到index.php,我会动态地从数据库中获取数据,然后向他们显示。

我的问题是所有的请求都要转到index.php,但我需要重定向,除了站点地图机器人&/admin文件夹

我的文件夹结构:

-example.com
-admin
-assets
-function
-views
.htaccess
index.php
config.php
sitemap.php
robots.txt

我的htaccess代码:

<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond %{THE_REQUEST} /([^.]+).php [NC]
#RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]
</IfModule>

就在RewriteEngine on行下方,您可以添加以下规则:

RewriteCond %{THE_REQUEST} s/+(?:sitemap.php|robots.txt|admin/) [NC]
RewriteRule ^ - [L]

最新更新