我正在使用 htaccess 进行动态 url 重写。我想将 test.php 显示为 test.html
htaccess 代码是
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [nc]
运行test.php后,浏览器在地址栏显示test.php。但如果我将 test.php 更改为 test.html,该页面将提供相同的内容。我的 apache 配置文件很好。我该如何解决这个问题? 感谢帮助我..
最佳答案
您不能拒绝访问您的 .php
你需要在 html 链接中放入你的 a 标签,它将在后台转到 php。
如果您仍然只想播种 html 地址,您可以将正则表达式放入您的 php 文件中,并检查扩展名是否为 php。如果是这样,将页面重定向到 html。
例子:
<?php
$temp = $_SERVER['PHP_SELF'];
$temp = explode('.', $temp);
if($temp[count($temp)-1] == "php"){
header("Location: test.html", true, 301);
}
?>
* 没尝过!!! *
关于php - 在 php 上使用 .htaccess 文件重写 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13340059/