Forum Moderators: phranque

Message Too Old, No Replies

htaccess wildcard 301 redirect

         

sgr2000

6:35 pm on Nov 26, 2010 (gmt 0)

10+ Year Member



I have a website that I moved to my Main website and I need to redirect the pages but dont know how to do it.

example

oldsite.com/xx-county-name1.html
oldsite.com/xx-county-name2.html

needs to redirect to

newsite.com/county/xx-county-name1.html
newsite.com/county/xx-county-name2.html

Is there a wild card I can use so I dont have to redirect each page.

like
Redirect 301 /xx-county-(wildcard code here).html http: //www.newsite.com/county/xx-county-(wildcard code here).html

any help is appreciated

g1smd

8:38 pm on Nov 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule, with [R=301,L] flags.

Capture both the county name and the wildcard from the URL request, using a Regular Expression pattern, and then take the back-references you created and re-use them in the target URL.

There are literally ten thousand similar examples of what you want to do, right here in this forum.

It is likely that a pattern something like
xx-([^-]+)-([^.]+).html 
will work. You can then re-use $1 and $2.

sgr2000

10:34 pm on Nov 26, 2010 (gmt 0)

10+ Year Member



that is greek to me. can you give me a code using the examples I gave ?
thanks

sgr2000

1:20 am on Nov 27, 2010 (gmt 0)

10+ Year Member



here is the real life pages

myalabamagenealogy.com/al-county-autauga.html
myalabamagenealogy.com/al-county-baldwin.html

needs to redirect to

familyhistory101.com/county/al-county-autauga.html
familyhistory101.com/county/al-county-baldwin.html

so on and so on. The are 67 countie for alabama and i need to redirect the other states as well. thats why i was needing one line of wildcard code i could use for each state. I am a novice at htaccess. so i needd and real example code and I can modify it for each state. Thanks

jdMorgan

8:58 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As g1smd has stated, it is likely that you only need one directive.

Please review our Apache Forum Charter [webmasterworld.com] to help make sense of the (accurate) response you've received so far.

Thanks,
Jim