Forum Moderators: phranque

Message Too Old, No Replies

Rewrite URL based on existance of a word in URL

         

pemba76

3:25 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



I have been trying to do the following.
I have about some 50 url's indexed in google but now i want all these to be permanently redirected to another url.
The url's are like this :
http://www.example.com/Fixwords-123456-dfghh
http://www.example.com/Fixwords-234567-fhjsh
http://www.example.com/Fixwords-345678-asdsd

Now i want these to redirect to:
http://www.example.com/Fixword-123456-dfghh
http://www.example.com/Fixword-234567-fhjsh
http://www.example.com/Fixword-345678-asdsd

Note - The only change to the url is:
Fixwords changes to Fixword (without the s)

I know this can be done manually by changing each and every url 1 by 1. But how is this done dynamically in htaccess file.

[edited by: jdMorgan at 4:15 pm (utc) on June 21, 2006]
[edit reason] example.com [/edit]

jdMorgan

4:16 pm on Jun 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But how is this done dynamically in htaccess file?

By the use of regular expressions to create a "back-reference" to store the parts of the requested URL you want to 'keep':


RewriteRule ^Fixwords-(.+)$ http://www.example.com/Fixword-$1 [R=301,L]

This is a fairly basic concept of mod_rewrite, and is well-documented; For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

pemba76

6:21 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



thanks jdMorgan,
actually i am quite new to this mod-rewrite world.

dmje

2:17 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



I have a question along the same lines.

I have pages in a subdirectory called metal, that begin with the word jewelry, such as

www.example.com/metal/jewelry4.html
www.example.com/metal/jewelry14-mag.html

Is it possible to key in on the word jewelry and redirect every instance regardless of what comes after the word jewelry?

I have seached high and low and cannot find the mod rewrite code I need to redirect pages like the above to another page.

jdMorgan

3:53 am on Jun 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is precisely what mod_rewrite and regular expressions are for.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

dmje

3:08 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



I have looked at all mentioned examples and still cannot figure out how to redirect those pages, everything I have tried has not worked. Can someone point me in the right direction on the proper code to use to accomplish this.