htaccess将url文件夹/file重写为文件夹/file.php


htaccess rewrite url folder/file to folder/file.php

我希望使用.htaccess将ajax/file地址重定向到ajax/file.php。我创建了一个如下所示的.htacccess文件,但它给出了500内部服务器错误。

RewriteEngine On
RewriteRule ^ajax/(.*)$ ajax/$1.php [L]

另外一个信息是,我的网站正在一个子文件夹下工作。(localhost/myproject)RewriteRule ^ajax/(.*)$ /ajax/$1.php [L]将url重定向到(localhost/ajax/file.php),而不是(localhost/myproject/ajax/fil.php)

问题是正则表达式中的.*也与file.php匹配。

像这样使用你的规则:

Options -MultiViews
RewriteEngine On
RewriteRule ^ajax/([^./]+)/?$ ajax/$1.php [L]