简体   繁体   English

.htaccess:用静态网址重写动态网址

[英].htaccess: Rewrite dynamic url with static url

I want to enter http://localhost:81/admin/dashboard in my browser but the request should be http://localhost:81/admin/index.php?page=dashboard . 我想在浏览器中输入http://localhost:81/admin/dashboard ,但请求应为http://localhost:81/admin/index.php?page=dashboard

The mod_rewrite is enabled and i tried this in the .htaccess but it didn't work. 启用了mod_rewrite,我在.htaccess中尝试了此操作,但没有成功。 The .htaccess is located in htdocs/admin/.htaccess: .htaccess位于htdocs / admin / .htaccess中:

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

You can match the trailing slash optionally by adding a ? 您可以通过添加来匹配尾部斜杠 next to it in the pattern : 在模式旁边:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM