通过 .htaccess 重定向多个 URL

编程入门 行业动态 更新时间:2024-10-27 18:22:49
本文介绍了通过 .htaccess 重定向多个 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有许多具有类似网址的页面,例如:

I have many pages with similar urls like:

example/mainpage/1 example/mainpage/2 example/mainpage/3 . .. example/mainpage/100

我想使用 .htaccess 将它们重定向到新的单个页面.喜欢:

I want to redirect them using .htaccess to new individual pages. Like:

  • example/mainpage/1 应该重定向到 example/mainpage-1
  • example/mainpage/2 应该重定向到 example/mainpage-2
  • example/mainpage/3 应该重定向到 example/mainpage-3
  • example/mainpage/1 should redirect to example/mainpage-1
  • example/mainpage/2 should redirect to example/mainpage-2
  • example/mainpage/3 should redirect to example/mainpage-3

等等.

因为有很多页面非常相似的网址,我想知道每种代码是否可以工作.

since there are many pages of very similar URLs, I want to know if a single code of each kind can work.

附言: 我对编码知之甚少.我的个人博客需要帮助

P.S. : I have little knowledge of coding. Need help for my personal blog

推荐答案

您能否尝试使用所示示例进行以下操作、编写和测试.请在测试 URL 之前清除浏览器缓存.第一个特定于显示的示例,将主页字符串保持在第一个反向引用中,并将 / 之后的其余数字保留在第二个反向引用中,我们在其右侧部分重定向时使用它们.

Could you please try following, written and tested with shown samples. Please clear your browser cache before you test your URLs. 1st one is specific to shown samples, keeping mainpage string into 1st backreference and rest digits after / in 2nd backreference which we are using them while redirecting on its right side part.

特定于样本:

RewriteEngine ON RewriteRule ^(mainpage)/([0-9]+)/?$ $1-$2 [R=302,NC,L]

通用:

RewriteEngine ON RewriteRule ^([\w-]+)/([0-9]+)/?$ $1-$2 [R=302,L]

更多推荐

通过 .htaccess 重定向多个 URL

本文发布于:2023-10-31 19:22:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   重定向   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!