我的索引页面的URL可以包含多个不同的变量,如:
index.php?page=page1
index.php?page=page2
index.php?page=page3
index.php?page=page4
我该如何使用.htaccess来缩短这些URL,使其看起来像这样:
index.php/page1
index.php/page2
index.php/page3
index.php/page4
谢谢。
您不需要为此重写规则。PHP中的PATH_INFO究竟是什么?
看看$_SERVER['PATH_INFO']
您也可以在.htaccess中使用以下代码来生成友好的URL(如果您想了解更多信息,这是您需要搜索的):
RewriteEngine On
RewriteRule ^(.*)$ ./index.php?page=$1
这将允许您使用
yourdomain.com/page1 => yourdomain.com/index.php?page=page1
yourdomain.com/page2 => yourdomain.com/index.php?page=page2
yourdomain.com/page3 => yourdomain.com/index.php?page=page3
yourdomain.com/... => yourdomain.com/index.php?page=...