RewriteRule ^/pages/topic\.php?tag=$1 /topics/([^/]+) [R=301,L]
RewriteRule ^topics/([^/]+)/?$ /pages/topic.php?tag=$1 [END]
我的问题在于 301 重定向,我相信问题在于 tag=$1
和 /([^/]+)
我不完全确定我已经正确完成了此操作,我想要的结果是,当用户导航到 /pages/topic.php?tag=cryptocom
时,用户将被重定向到 /topics/cryptocom/
感谢您的帮助。
最佳答案
根据您显示的尝试/示例,请尝试遵循 htaccess 规则文件。
在测试您的网址之前,请确保清除浏览器缓存。
RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/pages/([^.]*)\.php\?tag=(\S+)\s
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^topics/([^/]+)/?$ /pages/topic.php?tag=$1 [NC,QSA,L]
关于apache - htaccess 中的 url 参数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70858118/