.htaccess文件不适用于我的项目


.htaccess file not working on my project

我是PHP新手,正在尝试为我的web创建一个.htaccess文件
我已关注此链接:
mod_rewrite-windows-apache-url-rewrite已更改my C:''examplep''apache''conf''httpd.conf文件

这是我的.htaccess文件,保存在test文件夹下。

RewriteEngine On
RewriteRule localhost/admin/^([a-zA-Z0-9]+)$ localhost/test/application/admin/add_department.php?action=edit&page=$1
RewriteRule localhost/admin/^([a-zA-Z0-9]+)/$ localhost/test/application/admin/add_department.php?action=edit&page=$1

这是我的原始url
localhost/test/application/admin/add_department.php?action=edit&department_id=11

我希望它变成:
localhost/admin/add_department/11

但它不起作用,url栏仍然显示我的原始url
如果您需要任何信息,请告诉我,谢谢~~

不能使用RewriteRule匹配localhost

您还应该将.htaccess放置在您的网站根目录test/文件夹之上

你有这样的规则吗:

RewriteEngine On
RewriteBase /
RewriteRule ^(admin)/(['w-]+)/(['w-]+)/?$ test/application/$1/$2.php?action=edit&page=$3 [L,QSA,NC]

另请注意,使用/?$作为可选的尾部斜线。这将消除必须遵守2条规则的需要。

这将允许您在浏览器中使用localhost/admin/add_department/11 URL。