我需要的只是获取一个字符串作为 URL 而不显示 PHP 文件名.我有文件 contact.php 页面我正在尝试获取 URL例如
all I need is to get a string as URL without showing the PHP filename. I have file contact.php page I am trying to get URL as e.g.
本地主机/联系人.php
localhost/contact.php
这就是我现在得到的我需要访问这个页面
this is what now I am getting I need to access this page just with
本地主机/联系人
对于每个页面,我应该只能通过它们的名称导航.
For every page I should able to navigate by their name only.
本地主机/联系人
本地主机/帮助
本地主机/支持
localhost/contact
localhost/help
localhost/support
如果您使用的是 apache,则需要使用 .htaccess
文件.如果您使用的是 IIS,那么您可以在 IIS 中进行配置.
You need to use an .htaccess
file if you are using apache. If you are using IIS then you can configure it in IIS.
看看这个一>.
您的 .htaccess
文件需要如下所示:
Your .htaccess
file would need to look something like this:
IndexIgnore * # prevent directory listing
Order deny,allow
Allow from *
# ------------------------------------------
# Rewrite so that php extentions are not shown
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
由于文件限制,您不能在 windows 中简单地创建 .htaccess
文件,因此打开文本编辑器(Notepad ++ 或您的编程 IDE)并创建一个名为 .htaccess 的新文件代码>.
.
在文件名前面很重要.
You cannot simply create a .htaccess
file in windows because of file constraints, so open a text editor (Notepad ++ or your programming IDE) and create a new file called .htaccess
. The .
is important in front of the file name.
编辑
不要有重复的文件名.IE contact.php
和 contact.js
作为 htaccess
将不知道要提供哪个服务,哪个(取决于您的 apache)将返回一个错误页面,否则它只会提供其中一个.
Do not have duplicate file names. IE contact.php
and contact.js
as the htaccess
will not know which one to serve, which (depending on your apache) will either return an error page or it will serve one of them only.
正如@AedixRhinedale 在下面的评论中指出的那样:
As @AedixRhinedale pointed out in the comments below:
只是来自 Apache 的注释:你如果您有权访问 httpd 主服务器配置文件,则应完全避免使用 .htaccess 文件.使用 .htaccess 文件会降低 Apache http 服务器的速度.您可以在 .htaccess 文件中包含的任何指令最好设置在 Directory 块中,因为它具有相同的效果并具有更好的性能
Just a note from Apache: You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance
这篇关于没有 .php 扩展名的 PHP URL 格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!