使用1个指向page.php的参数编写干净的URL

问题描述

我希望访问者输入http://localhost/mywebsite/paris/ 它会调用http://localhost/mywebsite/page.PHP?city=paris

但是当键入http://localhost/mywebsite/时 它会调用http://localhost/mywebsite/index.PHP

RewriteEngine On
RewriteRule ([a-zA-Z-]*) /page.PHP?city=$1 [QSA,L]

我收到以下错误

Not Found
The requested URL was not found on this server.

解决方法

RewriteRule ^([a-zA-Z0-9]+)$ page.php?city=$1
RewriteRule ^([a-zA-Z0-9]+)/$ page.php?city=$1