.htaccess:用静态url重写动态url


.htaccess: Rewrite dynamic url with static url

我想在浏览器中输入http://localhost:81/admin/dashboard,但请求应该是http://localhost:81/admin/index.php?page=dashboard

mod_rewrite已启用,我在.htaccess中尝试过,但没有成功。.htaccess位于htdocs/admin/.htaccess:中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ index.php?page=$1  [NC]

您可以选择性地通过添加来匹配尾部斜杠模式中它的旁边:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1  [NC]