我想学习正则表达式和放大器; URL重写PHP中。如何创建一个.htaccess文件将改写(不定向)的任何网址的index.php?Q = {URL}
?
I'm trying to learn Regex & URL Rewriting in PHP. How can I create an .htaccess file which will rewrite (not redirect) any url to index.php?q={url}
?
例如:
http://www.example.com/baloon
到
http://www.example.com/index.php?q=baloon
我想:
RewriteEngine On
RewriteRule ^$ index.php?q=$1 [R]
...但它不工作。我究竟做错了什么?
...but it is not working. What am I doing wrong?
感谢。
重写任何URL的index.php Q = $ 1将会导致内部服务器错误,因为它会创建一个无限循环?;而不是做这样的事情:
Rewriting ANY url to index.php?q=$1 would result in internal server error as it'd create an endless loop; instead do something like this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ index.php?q=$1 [L]