如何从重写的URL中删除斜杠?

时间:2020-03-25 15:04:56

标签: url-rewriting

我有一个重写规则,将www.example.com/abc/product重写为www.example.com/abc/product

因此,当任何人使用斜杠或不使用斜杠访问www.example.com/abc/product/时,它都指向同一页面。如果有人决定手动插入www.example.com/abc/product,如何将/重定向到RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [R=301,L]

标准方法无效:

RewriteRule ^([A-Za-z0-9-]+)/product /product.aspx?product=${productmap:$1} [NC, L]

是否应该通过javascript进行重定向?这是RewriteRule:

  useEffect(() => {
    // swap the conditions to check for childRef first
    if (childRef && topPosition) {

      // use to get the size (width, height) of an element and its position
      // (x, y, top, left, right, bottom) relative to the viewport.
      const { y } = childRef.current.getBoundingClientRect()

      // You have to call `current` from the Ref
      // Add the `scrollTo()` second parameter (which is left)
      childRef.current.scrollTo(y, 0)

      // Initially it was set to `false` and we change it to `true` when click on scroll
      // button then we change it back to `false` when re-render 
      setTopPosition(false)

    }
  }, [topPosition, childRef])

0 个答案:

没有答案