views:

36

answers:

1

Hi,

I'm trying to rewrite the following into htaccess using - redirect 301

redirect "mysite.com/longname/{20 character string}" to "mysite.com/shortname/{10 character string}"

basically to redirect the "longname" to "shortname" and cut the "20 character string" to the first 10 characters

so when I go to mywebsite.com/longname/aaaaabbbbbcccccddddd, it rewrites it into mywebsite.com/shortname/aaaaabbbbb

Here's what I have so far:

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

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/.

mopoke
Thanks.Your code worked, minus the initial slash before "longname" (thanks Max S.)
tim