在apache服务器上的文件夹(dir)中隐藏php扩展

在apache服务器上的文件夹(dir)中隐藏php扩展,php,apache,.htaccess,ftp,server,Php,Apache,.htaccess,Ftp,Server,我正在使用apache服务器simple和mod_dir,类似这样的东西。我的php文件是changePassword.php,它重定向到psswdChanger文件夹 <?php /* Redirect browser */ header("Location: ./psswdChanger/"); /* Make sure that code below does not get executed when we redirect. */ exit; ?> 我需要隐藏.ph

我正在使用apache服务器simple和mod_dir,类似这样的东西。我的php文件是changePassword.php,它重定向到psswdChanger文件夹

<?php
/* Redirect browser */
header("Location: ./psswdChanger/");

/* Make sure that code below does not get executed when we redirect. */
exit;
?>


我需要隐藏.php exptension,因此我希望在我的目录中只包含changePassword文件,该文件将重定向到psswdChanger文件夹(.php扩展名必须隐藏)。它不仅可以是php文件,还可以是其他类型的文件,可以重定向到psswdChanger文件夹,但没有扩展名

正如您所说,您正在运行apache服务器,最简单的方法是将.htaccess文件保存在php文件所在的目录中

在htacess文件中添加:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

这将把changePassword.php重写为/changePassword-但是我不得不问,你为什么要隐藏文件扩展名?

Google“apache url rewriting”如果你将“psswdChanger/”重写回你的changePassword.php文件,它只会再次重定向,导致重定向循环。这与url重写无关,我需要在服务器上的目录中隐藏php扩展,我不想编辑URL地址。如果尝试转到不存在的页面,这将失败,将导致500服务器错误。也不能解释尾随斜杠。它是失败的,在我写这篇文章之前,我还尝试了.htaccess。扩展仍然存在,如果我单击changePassword.php,它会显示错误,因为在此服务器上找不到请求的URL/test4/psswdChanger/.php。