如何使用 HTaccess 将网站链接显示为 HTML 而不是查询字符串


how to show website links as html rather than querystring using htaccess

我有如下网站链接。

justrite.pl/exam.php?code=/product1.htm

justrite.pl/exam.php?code=/product2.htm

justrite.pl/exam.php?code=/product3.htm

以及许多产品,如产品4,产品5......产品100

如果有人访问该网站,应该看到下面给出的这些链接

justrite.pl/product1.htm

justrite.pl/product2.htm

justrite.pl/product3.htm

请帮助使用 HTaccess实现它。

您可以像这样使用.htaccess规则:

RewriteRule ^product1.htm$ exam.php?code=product1.htm [L]
RewriteRule ^product2.htm$ exam.php?code=product1.htm [L]
RewriteRule ^product3.htm$ exam.php?code=product1.htm [L]

尽可能添加更多。

这应该可以做到:

RewriteEngine on
RewriteCond   %{REQUEST_FILENAME}   !-d
RewriteCond   %{REQUEST_FILENAME}   !-f
RewriteRule   (.*)                  /exam.php?code=$1   [L]

它还检查是否有具有最初请求名称的目录或文件,以便它不会重定向它们。