Apache在URL中隐藏查询字符串,但保持URL正常工作

mm5n2pyu  于 2023-03-19  发布在  Apache
关注(0)|答案(1)|浏览(120)

我有两种类型的网址,但他们可以有任何查询字符串后,因为我们有1000的网址/职位。
两者都有/?id=/,我希望隐藏/删除它,但页面仍然加载。
这些页面是wordpress中的自定义插件,我在Apache2.4中没有启用.htaccess,因此需要通过.conf规则来完成
有谁能帮忙吗?这两种URL类型是:
https://example.com/news-and-events/news/?id=/kanpai-pandas/@KanpaiPandas/the-largest-airdrop-competition-in-web3-dd6f8f78c758
以及
https://examples.com/news-and-events/event/?id=/e/crypto-for-lawyers-in-60-minutes-watch-on-demand-tickets-363441371927
WordPress安装根目录位于/新闻与事件/
我可以删除查询字符串,但结果是404,而不是原始内容/页面,这似乎不起作用。
谢谢你Rob
我目前拥有的代码:
重写引擎打开
重写条件%{查询字符串} ^(.)?ID=(.)?$ [NC]
重写规则^(.*)?$$1%2?[R=301,L]

0tdrvxhp

0tdrvxhp1#

在〈VirtualHost *:80〉容器中尝试以下操作:

<Directory "/var/www/vhosts/myhost/htdoc/news-and-events/news/">

    RewriteBase "/news-and-events/news/"
    RewriteCond "%{QUERY_STRING}" ""
    RewriteRule "(.*)" "index.php?id=/$1" [L]

</Directory>

请查看您的其他请求以了解更多详细信息。
需要Apache重写器规则协助
你是对的PHP脚本也需要一些定制。
Php to remove query string in URL but keep URL working
最后,最好把所有内容作为一个任务来编写,并且以一种有据可查的方式来编写。

相关问题