如何使用 .htaccess 将用户重定向到同一网站上的新网址?

发布于 2024-12-23 08:03:42 字数 277 浏览 0 评论 0原文

我最近更改了网站的网址。

旧网址:mysite.com/top/1

新网址:mysite.com/top/page=1

当用户访问旧网址时,我想将他们重定向到新网址。我怎样才能用.htaccess 做到这一点?

我有新网址的重写规则

RewriteRule ([top,new]+)/page=([0-9]+) index.php?h=$1&page=$2 [L]

I recently changed URLs of my site.

Old URL: mysite.com/top/1

New URL: mysite.com/top/page=1

When the users visit old url I want to redirect them to new url. How can I do it with .htaccess?

i have this rewrite rule for new url

RewriteRule ([top,new]+)/page=([0-9]+) index.php?h=$1&page=$2 [L]

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

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

发布评论

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

评论(2

宛菡 2024-12-30 08:03:42

试试这个

RewriteEngine On
RewriteRule ^top/([0-9]+)$ top/page=$1 [R=301,L]

Try this

RewriteEngine On
RewriteRule ^top/([0-9]+)$ top/page=$1 [R=301,L]
邮友 2024-12-30 08:03:42

对于你原来的问题,你应该尝试这样的事情:

RewriteRule ^top/([0-9]+)$ top/page=$1

但是根据你对 Virendra 帖子的评论,这可能会更好地满足你的需求:

RewriteRule ^(top|new)/([0-9]+)$ index.php?h=$1&page=$2 [R=301,L]

这将匹配 top 和 new,并且仅在指定了有效页码的情况下重写。

希望这有帮助

For your original question, you should try something like this:

RewriteRule ^top/([0-9]+)$ top/page=$1

But according to your comment on Virendra's post, this will probably better suite your needs:

RewriteRule ^(top|new)/([0-9]+)$ index.php?h=$1&page=$2 [R=301,L]

This will match both top and new, and rewrite only if a valid page number is specified.

Hope this helps

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