我希望使用我的网站的人在浏览器地址栏中查看site.com/contact以代替site.com/index.php?page=contact。
我是mod_rewrite的新手,到目前为止,我已经达到了这条规则。
我现在的代码是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1
我怎么做到这一点?
编辑:问题是我的联系页面的URL仍然显示:site.com/index.php?page=contact。
最后一部分RewriteRule应如下所示:
RewriteRule ^(contact)/?$ index.php?page=$1
这意味着如果用户键入“mysite.com/contact”,他们实际上正在提供“mysite.com/index.php?page=contact”。
括号创建捕获组,转换为$1
。对于每个连续的括号,捕获组变量递增 - $2
,$3
等。