.htaccess htaccess中的基本重写规则不起作用

.htaccess htaccess中的基本重写规则不起作用,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我是htaccess的新手,我一直在尝试做一个非常简单的重定向:localhost/profiletest应该显示localhost/profile 这是我的.htaccess: RewriteEngine on # Remove ".php" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [NC] # This i

我是htaccess的新手,我一直在尝试做一个非常简单的重定向:localhost/profiletest应该显示localhost/profile

这是我的.htaccess:

RewriteEngine on

# Remove ".php"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC]

# This is the rule that does not work:
RewriteRule ^/profiletest$ /profile.php

# 404 page
ErrorDocument 404 /404.php
第一条规则(删除“.php”)可以正常工作

但是localhost/profiletest显示的是404页面,而不是概要文件页面。我做错了什么?(如果上面有另一条规则,配置文件规则中的“.php”是否必要?)

我还尝试简化我的HTC访问:

RewriteEngine on
RewriteRule ^/profiletest$ /profile.php

# 404 page
ErrorDocument 404 /404.php

使用相同的结果(/profiletest显示404页)。

通过.htaccess配置时,URL路径重写规则匹配,从不以前导斜杠开头,这一点已经去掉了。@CBroe非常感谢,这是我的错误!