1

I cannot figure out how to replace a string in a htaccess file. I need to change all of the urls on the site, currently they are formatted like this.

site.com/218-111-home/straight-black-mid-length-ladies-purse.jpg

and I need to redirect them to targets like this:

site.com/111-home/straight-black-mid-length-ladies-purse.jpg

I have tried for the life of me to get it to work, but I basically do not know how to take off the first three numbers after the domain and the -

Regex has beaten me.

2
  • What do you mean by "change the urls"? Do you want your users, when visiting the links like 218-111-home/ to be redirected to 111-home/ changing their browser address, or just be sent internally and silently to content at 111-home/? If you mean to physically change the links in your content, Apache URL rewriting can't actually do that... Commented Feb 11, 2014 at 21:43
  • I am looking for it to redirect the first link to the second link. Sorry I wasn't clear. Commented Feb 11, 2014 at 21:46

1 Answer 1

1

You can try this RedirectMatch rule:

RedirectMatch 301 ^/[0-9]+-([0-9]+-.+)$ /$1
Sign up to request clarification or add additional context in comments.

3 Comments

That kills the existing images. The urls of the images have changed from the first url and now they are all like the second url. What I am trying to accomplish to redirect the first images to the new image path.
But this is what this rule is doing. It just strips 218- from the from of URL.
Correct it does, but it also strips it out of the urls like this, site.com/111-home/straight-black-mid-length-ladies-purse.jpg which is the new url structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.