我可以使用 HTACCESS 来格式化这个 URL 吗?

Can I use HTACCESS to format this URL?

我想知道是否可以将 URL 格式化为 https://site1.com/en/article-details.test-article?item=testhttps://site1.com/en/article-details/test-article?item=test,从而基本上将 .test-article 更改为 /test-article

由于我的网站的工作方式,它仅将 .test-article 识别为有效选择器,因此阅读 https://httpd.apache.org/docs/2.4/rewrite/flags.html 看来我可能需要使用 PT 标志向用户显示需要 URL 但将正确的传递到我的网站。

到目前为止,我用这个来替换斜杠的点

RewriteCond %{REQUEST_URI} ^/([a-z]{2})/article-details.([a-z]{2})(/?)$
RewriteRule ^/([a-z]{2})/.*  https://%{SERVER_NAME}// [L,NC,R=301]

编辑(这可以根据 RavinderSingh13 的建议格式化 URL)

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/article-details.([^?]*)(/?)$
RewriteRule ^ https://%{SERVER_NAME}/%1/article-details/%2 [QSA,R=301,NE,L]

根据您展示的示例,请您尝试以下操作。请确保在测试您的 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(en/article-details)\.(test-article)\?item=test\s [NC]
RewriteRule ^ https://site1.com/%1/%2 [QSA,R=301,NE,L]

根据 OP 的评论,在此处添加更多通用规则:

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(en/article-details)\.([^?]*)\?item=test\s [NC]
RewriteRule ^ https://site1.com/%1/%2 [QSA,R=301,NE,L]

您可以尝试将此规则作为最重要的规则:

RewriteEngine On

RewriteRule ^(.+)\.(test-article/?)$ // [R=302,NE,L,NC]

测试此规则后将 302 更改为 301