我正在尝试将URL重写为页面,在该页面中应该找到一个标签。

RewriteEngine On
RewriteRule ^/posts/hashtag/([a-zA-Z0-9_-]+)$ index.php?url=posts&hashtag=$1


但是这种方式似乎行不通。
例如如果$ 1的值很有趣,则输出应为domain.com/posts/hashtag/funny,但不是。

最佳答案

像这样尝试,当您在浏览器中输入url domain.com/posts/hashtag/funny时,它将在内部重写为index.php?url=posts&hashtag=$1

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^posts/hashtag/([\w-]+)$ index.php?url=posts&hashtag=$1 [QSA,L]

10-08 02:36