首页 > 解决方案 > .htaccess 重定向到 .php 文件时未加载任何资源(img、js、css)

问题描述

我想将没有扩展名的页面重定向到 php 文件。例如
https://example.com/starrysky/ => https://example.com/starrysky.php
我已经有一个从 HTML 到 PHP 的有效重定向:
https://example.com/starrysky.html正确重定向https: //example.com/starrysky.php

当我在.htaccess中将.html重定向到.php时,它完美地工作:它将.html重定向到.php,所以我想,用(以斜杠结尾)替换最后一个会重定向到 php ,但这不起作用。.html$/$

这确实有效

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

但这不会:

# RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/$ $1.php

在最后一行的斜杠 + 美元前面加上反斜杠将无济于事。并且取消注释上面的 RewriteCond 行也对我没有帮助。

我希望https://example.com/starrysky/重定向到https://example.com/starrysky.php

确实如此,但没有加载 css、js 和图像,尽管它们是相对于同一个文档根目录的。

标签: phpapacheredirect

解决方案


推荐阅读