Welcome to WebmasterWorld Guest from 35.172.195.49

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

neighborhood url 301 redirect issues

     
5:42 pm on Apr 24, 2015 (gmt 0)

New User

joined:Apr 24, 2015
posts: 1
votes: 0


Spent several hours trying to find the right answers... and testing codes.. Even used redirect plug ins...

Just switched example.com from Dreamweaver html site to a wordpress site to keep up with the Google mobile restrictions. I now need to create 301 redirects for individual pages, however the redirects are to a subdomain with pages generated automatically through an IDX provider (real estate).

For example I want to 301 redirect:

http://example.com/Neighborhood_Homes_for_Sale.html to http://search.example.com/i/neighborhood-city-name-state

using the htaccess file.

Your guidance in this matter is greatly appreciated.

Mark Z

[edited by: phranque at 10:05 pm (utc) on Apr 24, 2015]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

10:23 pm on Apr 24, 2015 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11871
votes: 245


welcome to WebmasterWorld, Mark!


you will need some way to associate the extracted neighborhood name with its city name and state.
it is possible to do this using one-to-one redirects of old urls to new urls.
RewriteRule ^Neighborhood1_Homes_for_Sale\.html$ http://search.example.com/i/neighborhood1-city1-name-state1 [R=301,L]
RewriteRule ^Neighborhood2_Homes_for_Sale\.html$ http://search.example.com/i/neighborhood2-city2-name-state2 [R=301,L]
...


another possibility is to recognize the pattern of these urls and internally rewrite these to a script that responds with the proper redirect using a lookup table or database for the association while reconstructing the url.

RewriteRule ^([A-Z]\w+)_Homes_for_Sale\.html$ /redirect-script.php?neighborhood=$1 [L]


redirect-script.php would look up the value of the "neighborhood" parameter to retrieve the city name and state, construct a new url, and return the following response:
301 Moved Permanently
Location: http://search.example.com/i/neighborhood-city-name-state

[edited by: phranque at 10:01 pm (utc) on Apr 25, 2015]

12:47 am on Apr 25, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15934
votes: 889


redirect-script.php?neighborhood=$1

... and when your fingers typed "redirect-script" your brain meant "/redirect-script" with leading / slash so no nasty robot can slip in and say All your RewriteBase are belong to us, or whatever it is that g1smd was always warning about ;)

When you rewrite to a php thingy, doesn't the server remember the originally requested URL? I thought it did, so you don't need to capture or pass any values.

MarkZ, another thing your hypothetical php script can do with the greatest of ease is to change everything from Title_Case or CamelCase to lower-case throughout. Doing it within htaccess, without the built-in RewriteMap, can be slightly hellish.
8:29 pm on Apr 25, 2015 (gmt 0)

New User from US 

5+ Year Member

joined:Feb 18, 2014
posts: 30
votes: 4


MarkZ:

I like to use a plugin called Redirection by John Godley. It makes things simple and easy and doesn't make you muc up your htaccess files.

If you're new to WordPress, it would be your easiest route. If you remove the wrong things from your htaccess file - or improperly order them - you could cause issues with WordPress functionality.
10:03 pm on Apr 25, 2015 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11871
votes: 245


when your fingers typed "redirect-script" your brain meant "/redirect-script" with leading /

yes.
so edited.