【问题标题】:how to show website links as html rather than querystring using htaccess如何使用 htaccess 将网站链接显示为 html 而不是查询字符串
【发布时间】:2016-04-19 17:11:05
【问题描述】:

我有下面给出的网站链接。

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

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

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

还有很多产品,比如product4、product5......product100

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

justrite.pl/product1.htm

justrite.pl/product2.htm

justrite.pl/product3.htm

请帮助使用 htaccess 实现它。

【问题讨论】:

    标签: php .htaccess querystringparameter


    【解决方案1】:

    您可以像这样使用.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]
    

    尽可能多地添加。

    【讨论】:

    • 我希望我能得到一个单一的重写规则,而不是输入 100 次重写规则。
    • 重写规则 ^(.*).htm$exam.php?code=$1.htm [L] @SNazia
    【解决方案2】:

    应该这样做:

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

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

    【讨论】:

      猜你喜欢
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多