我在将虚拟目录重写为变量时遇到问题..有人可以帮忙吗?
网址是: https://www.example.com/content/index.php?var=1-dKein4i59xcNjfks
我希望它看起来像: https://www.example.com/content/featured/1-dKein4i59xcNjfks
其中“content”是真实目录,“featured”和“1-dKein4i59xcNjfks”是虚拟目录 我当前的 .htaccess 代码不正确:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ content/index\.php\?var=([^\&\ ]+)
RewriteRule ^content\/?index\.php$ /var/%1? [L,R=301]
有人可以帮忙吗?谢谢
使用您显示的示例,请尝试以下操作。确保在测试之前清理浏览器缓存。
RewriteEngine ON
##Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(content)index\.php\?var=(?:.*?)\s [NC]
RewriteRule ^ /%1/featured/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(content)/featured/(.*?)/?$ $1/index.php?var=$2 [QSA,NC,L]