【问题标题】:How to redirect to sitemap.php from htaccess如何从 htaccess 重定向到 sitemap.php
【发布时间】:2011-06-23 23:09:21
【问题描述】:

我正在使用从 wordpress 复制的 htaccess。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
重写规则。 index.php [L]

它工作正常。

如果用户请求 sitemap.xml,我想添加一个脚本以重定向到 sitemap.php 文件。

我尝试添加RewriteCond %{REQUEST_FILENAME} !-^sitemap.xml$,但没有成功。

【问题讨论】:

    标签: wordpress .htaccess redirect sitemap


    【解决方案1】:

    将规则放在那组规则之前:

    RewriteRule sitemap\.xml sitemap.php [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

    • [L] 标志表示最后一个,这意味着如果触发该规则,则重写引擎不应再读取和处理任何规则。一旦对 sitemap.xml 的请求与该规则匹配并被重写为 sitemap.php,Apache 就不会读取将请求重写为 WordPress 的其余规则。
    猜你喜欢
    • 2013-05-20
    • 2019-02-21
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    相关资源
    最近更新 更多