我有许多具有类似网址的页面,例如:
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
发布评论