简体   繁体   English

htaccess修改字符串然后重定向301

[英]Htaccess Modify String then Redirect 301

I'm trying to rewrite the following into htaccess using - redirect 301 我正在尝试使用-重定向301将以下内容重写为htaccess

redirect "mysite.com/longname/{20 character string}" to "mysite.com/shortname/{10 character string}" 将“ mysite.com/longname/{20字符串}”重定向到“ mysite.com/shortname/{10字符串}”

basically to redirect the "longname" to "shortname" and cut the "20 character string" to the first 10 characters 基本上是将“ longname”重定向到“ shortname”,并将“ 20 string”切成前10个字符

so when I go to mywebsite.com/longname/aaaaabbbbbcccccddddd, it rewrites it into mywebsite.com/shortname/aaaaabbbbb 因此,当我访问mywebsite.com/longname/aaaaabbbbbcccccddddd时,它将其重写为mywebsite.com/shortname/aaaaabbbbb

Here's what I have so far: 这是我到目前为止的内容:

RewriteEngine On
RewriteRule /longname/(.*) /shortname/$1 [R=301,L] 

You should be able to limit the input using a regular expression such as: 您应该能够使用正则表达式来限制输入,例如:

RewriteEngine On
RewriteRule /longname/(.{0,10}) /shortname/$1 [R=301,L] 

This will match a string of 0-10 characters following /longname/. 这将匹配/ longname /之后的0-10个字符的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM