如何使用 .htaccess 成功重写 URL
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
操作方法如下:
这将确保无论您使用哪个域,如果您拥有正确的组合,它总是会匹配,例如,如果将来您决定更改域,则更容易。
更新
我不小心在我的示例中使用了 (.*) 两次,但它已被修复
希望这对您有帮助
Here's how you do it:
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
从 /feeds/ 中删除尾随 / ;-)
至少 - 这现在对我有用
remove trailing / from /feeds/ ;-)
at least - this works for me right now
添加
in your .htaccess file.
If it doesn't work, try add
in the top of your file.
Add
in your .htaccess file.
If it doesn't work, try add
in the top of your file.