2

I am moving hosts and the URL structure will change as the new site (same domain name) will be done the Wordpress.

I have many URL's where the first part of the page name is the same and they all need to be redirected to a single page on the new site. For example.

  • http://www.example.com/binfet-timeinthepark.htm
  • http://www.example.com/binfet-backtothecity.htm
  • http://www.example.com/binfet-justmeetmehalfway.htm

all need to go to:

http://www.example.com/bev-binfet/

Is there a way to write a rule to capture all of these? There are about 50 different cases ie. In this example "binfet" is at the beginning but are about 50 different names.

UPDATE

In response to @Fayaz

I have about 50 cases where the URL's begin with the same name but then have different endings. For each case all URL's for that case go to a single new page.

Eg.

http://www.example.com/xyz-sometext.htm http://www.example.com/xyz-someothertext.htm ... all go to a single new URL

http://www.example.com/xyznewplace/

  • 1
    OK, does the new URL have any pattern with the old group of URLs? For example, if http://www.example.com/xyz-sometext.htm redirects to http://www.example.com/xyz-new, can I say from it that http://www.example.com/abc-someothertext.htm will redirect to http://www.example.com/abc-new? The reason I'm asking is because if there is a pattern then your rewrite will be small, otherwise you'll have to write 50 RewriteRule, one for each group. – Fayaz Feb 6 '17 at 11:58
1

Solution:

I suggest you use the full URL in RewriteRule.

So for all the URLs that start with binfet to go to /bev-binfet/, you need to add the following directive in your .htaccess file (before other Rewrite Rules):

RewriteRule ^binfet http://www.example.com/bev-binfet/ [R=301,L]

Reason:

Most likely you have other rules that redirect non-www links to www links. So in that case using the full URL will avoid additional redirects. For example, someone tries to access:

http://example.com/binfet-timeinthepark.htm

Without the full URL in RewriteRule it'll first redirect to:

http://example.com/bev-binfet/

and then, finally:

http://www.example.com/bev-binfet/

With the solution mentioned here, you'll avoid the first redirect & go directly to:

http://www.example.com/bev-binfet/

Further Query:

For some reason, I feel like there is more to your question. You said:

There are about 50 different cases ie. In this example "binfet" is at the beginning but are about 50 different names.

A. Did you mean there are 50 URLs where the URL starts with a particular phrase (for example binfet)?

or

B. Did you mean there are 50 such starting phrases (like one group of URLs starting with binfet, another group of URLs starting with xyz etc.) and each group ends up in a unique url?

If A is the case then the solution given here is enough. However, if B is the case, then either you'll have to write this rule 50 times for each starting phrase or you'll have to find a better pattern that can cover all of them.

Please update your question with more details if B is the case.

| improve this answer | |
0

In this example "binfet" is at the beginning but are about 50 different names.

To redirect all URLs that start binfet then try the following mod_rewrite directive before your existing WP directives in your .htaccess file:

RewriteRule ^binfet /bev-binfet/ [R=301,L]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.