将 apache2 @username 的 URL 重写为 /user/username

发布于 2025-01-15 16:18:04 字数 263 浏览 4 评论 0原文

这相当简单,但我很难弄清楚该怎么做,我在 apache2 rewriteurl 文档中进行了搜索,但没有找到任何有用的东西。 你转到 url.com/@myusername ,apache 会将你指向 url.com/username/@myusername 并在浏览器上保持 URL 完整,并带有 [L,NE,P]

RewriteURL @username /user/username

请注意,我只想重定向以 @ 符号开头的内容并将其作为用户名

This is fairly simple but I am having a hard time figuring out what to do I searched in the apache2 rewriteurl documentation but didnt find anything helpful.
you go to url.com/@myusername and apache points you to url.com/username/@myusername and keeps the URL on the browser intact with [L,NE,P]

RewriteURL @username /user/username

please note I only want to redirect what starts with @ sign and take it as a username

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-01-22 16:18:04

首先激活mod_rewrite,

sudo a2enmod rewrite

然后重新启动apache2,

sudo systemctl restart apache2

在Web根目录中创建.htaccess文件。这必须是您在 apache 配置中提供的文档根目录。

RewriteRule ^([A-Za-z0-9]+) user/$1 [QSA]

更新

如果您希望匹配以@符号开头,请使用如下正则表达式,

RewriteRule ^(@[A-Za-z0-9]+) user/$1 [QSA]

First activate mod_rewrite,

sudo a2enmod rewrite

Then restart apache2,

sudo systemctl restart apache2

create the .htaccess file in the web root. This must be the document root you provided in the apache config.

RewriteRule ^([A-Za-z0-9]+) user/$1 [QSA]

UPDATE

If you want the match start with @ symbol, use the regex as below,

RewriteRule ^(@[A-Za-z0-9]+) user/$1 [QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文