htaccess文件来制作干净的网址

时间:2017-02-22 05:22:39

标签: php .htaccess

我正在使用wamp服务器,它包含我的项目文件夹testCase,其中包含几个php文件

testCase
  - view.php
  - add.php
  - delete.php
  - .htaccess

在.htaccess文件中,我有像

这样的代码
RewriteEngine on
RewriteRule ^view?$ view.php

我正在尝试使用url运行我的项目" localhost / testCase / view"而不是" localhost / testCase / view.php"结果为未找到

我在stackoverflow中找到了很多关于这个htaccess的教​​程。由于我是编程的初学者,我无法解决这个问题。任何人都可以帮助我。即使我得到投票或重复的问题,我也很想解决我的问题。

谢谢。

1 个答案:

答案 0 :(得分:0)

你想删除.php扩展名,

尝试以下规则,

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

上面将适用于testcase目录中的所有php文件。

相关问题