如何使用 .htaccess 成功重写 URL

发布于 2024-08-26 21:17:16 字数 331 浏览 4 评论 0原文

我正在尝试将 mysite.com/broadcasts 重写为 mysite.com/feed,以便它将在地址栏中显示为“broadcasts”,但实际上会转到 /feed。

这是我在 .htaccess 文件中的内容:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^broadcasts(/)?$ /feed/ 
</IfModule>

但这不起作用...我收到 404 错误。

想知道我是否做了一些愚蠢的错误事情。

谢谢!

I am trying to rewrite mysite.com/broadcasts to mysite.com/feed so that it will show up in the location bar as "broadcasts" but actually go to /feed.

Here is what I have in the .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^broadcasts(/)?$ /feed/ 
</IfModule>

But this isn't working... I get a 404 error.

Wondering if I'm doing something stupidly wrong.

Thanks!

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

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

发布评论

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

评论(3

猫性小仙女 2024-09-02 21:17:16

操作方法如下:

RewriteRule ^(.*)/broadcasts$ $1/feed/ 

这将确保无论您使用哪个域,如果您拥有正确的组合,它总是会匹配,例如,如果将来您决定更改域,则更容易。

更新
我不小心在我的示例中使用了 (.*) 两次,但它已被修复

希望这对您有帮助

Here's how you do it:

RewriteRule ^(.*)/broadcasts$ $1/feed/ 

This will make sure no matter what domain you use, it will always be matched if you have the right combination, making it easier if in the future you decide to change domains for example.

UPDATE
I accidentally used (.*) twice on my example, but it has been fixed

Hope this helps you

单调的奢华 2024-09-02 21:17:16

从 /feeds/ 中删除尾随 / ;-)

至少 - 这现在对我有用

remove trailing / from /feeds/ ;-)

at least - this works for me right now

晚雾 2024-09-02 21:17:16

添加


RewriteRule ^broadcasts feed

in your .htaccess file.
If it doesn't work, try add


RewriteEngine on
RewriteBase /

in the top of your file.

Add


RewriteRule ^broadcasts feed

in your .htaccess file.
If it doesn't work, try add


RewriteEngine on
RewriteBase /

in the top of your file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文