在 HTACCESS 重写并使用 $_SERVER['PHP_SELF'] 后,页面源代码仍显示原始页面名称

Page Source is still showing the original page name after HTACCESS rewrite and using $_SERVER['PHP_SELF']

我正在使用 htaccess 重写将名为 cities.php 的页面的名称更改为单击时 linked 的城市页面。例如,如果单击 Aliso Viejo 的 link,您将看到:

aliso-viejo-slab-leak-detection.php

我的htaccess重写部分如下:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
    RewriteRule ^([a-z]+)-slab-leak-detection.php$ cities.php?city=&state=
    RewriteRule ^([a-z-]+)-slab-leak-detection.php$ cities.php?city=&state=
    RewriteRule ^(.*)\.html$ .php [L]
    ErrorDocument 404 /index.php

现在重写工作如期进行。问题是我正在使用的规范 link:

    $_SERVER['PHP_SELF']

回显页面 url 以建立索引。它不是回显重写的页面名称,而是回显原始 cities.php 名称。搜索引擎也正在为预先重写的页面编制索引。

我假设我的代码顺序错误或没有正确编码以静默而不是动态编写。

请记住,我对高级 httaccess 编码非常不熟悉,我使用的代码来自我研究过的更改信息。

非常感谢任何帮助。

我认为 $_SERVER['PHP_SELF'] 的值不受 .htaccess 重写的影响,因为它引用文件系统,而不是 URL。

如果需要引用 URL,请使用 $_SERVER['REQUEST_URI']

编辑

刚刚找到相关 question/answer:Can PHP access the .htaccess rewrite name of a file。 Regilero 对所选答案的评论很好地说明了在输出之前转义 $_SERVER['REQUEST_URI'] 的值:

Beware that you should escape $_SERVER['REQUEST_URI'] before using to build HTML content, avoid users injection HTML/js in the url. Check whosebug.com/a/326331/550618 for details on SCRIPT_NAME vs REQUEST_URI