: .htaccess how to redirect multiple pages to one? 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
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.
www.example.com/binfet-timeinthepark.htm http://www.example.com/binfet-backtothecity.htm www.example.com/binfet-justmeetmehalfway.htm
all need to go to:
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.
www.example.com/xyz-sometext.htm www.example.com/xyz-someothertext.htm ...
all go to a single new URL
www.example.com/xyznewplace/
More posts by @Lengel546
2 Comments
Sorted by latest first Latest Oldest Best
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 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:
example.com/binfet-timeinthepark.htm
Without the full URL in RewriteRule it'll first redirect to:
example.com/bev-binfet/
and then, finally:
www.example.com/bev-binfet/
With the solution mentioned here, you'll avoid the first redirect & go directly to:
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.