Forum Moderators: phranque
I'm trying to rewrite some URLs that do not exist anymore to the new URLs.
The old URLs are:
http://www.example.com/property.php?city=Gotham&state=NY&type=xyz
The new URL needs to be:
http://www.example.com/list/index.php?location=Gotham&type=xyz
I'd appreciate any help with this. I'm not so great at regex.
Thanks
theMaab
[edited by: jdMorgan at 12:14 am (utc) on Aug. 18, 2008]
[edit reason] example.com [/edit]
Of course my old URLs are the ones indexed by SEs. I want to salvage the traffic that comes from those, so they do not get a 404.
Sorry, I should have been more clear in my question.
BTW, thanks for the quick responses, that was pretty awesome.
.
I believe you'll need something like this:
RewriteCond %{QUERY_STRING} ^city=(.*)&state=NY&type=xyz
RewriteRule ^property\.php http://www.example.com/list/index.php?location=%1&type=xyz [R=301,L]
There will be a better way to optimise that, as .* is greedy. Perhaps use ([^&]+) or something.
.
I also don't like "index.php" in a URL so I might actually go for this instead:
RewriteCond %{QUERY_STRING} ^city=([^&]+)&state=NY&type=xyz
RewriteRule ^property\.php http://www.example.com/list/?location=%1&type=xyz [R=301,L]
.
In addition I would add something like:
RewriteCond %{THE_REQUEST} list/index\.php
RewriteRule ^list/index\.php http://www.example.com/list/ [R=301,L]
to always remove the "index.php" from the URLs. The original query string should be re-appended on the end.
On my own sites I wouldn't need that specific rule as I always redirect for all common index file names, to remove the index filename and preserve the rest of the URL.
[edited by: jdMorgan at 12:15 am (utc) on Aug. 18, 2008]
[edit reason] example.com [/edit]
I don't understand why you don't jump to completely static-looking URLs like:
www.example.com/list/Gotham/xyz
To do that you would have:
1. A redirect from the old dynamic URL to the new static URL with [R=301,L]
2. A rewrite from the static-looking URL to the internal dynamic filepath with [L]
3. The static-looking URLs within the links in the content of your site.
[edited by: jdMorgan at 12:16 am (utc) on Aug. 18, 2008]
[edit reason] example.com [/edit]
www.example.com/list/Gotham/xyz
And I like your idea to remove the index.php from the URLs to. Just unnecessary.
How ever there are other Query String parameters that I would need to carry over as well. Like
www.example.com/list/Gotham/xyz?b=4&c=3
I should have included this in my original post too, I just wanted to keep it simple and to the point.
[edited by: jdMorgan at 12:17 am (utc) on Aug. 18, 2008]
[edit reason] example.com [/edit]
Before you start, you have to be clear what all the dynamic internal formats look like, and then choose static-looking URL formats that will be easy to test to discover which internal format they need to be rewritten to.
Write them all down. Mull it over for a day or two. At this point I fall back on the "Measure twice. Cut once." school of thought.
I've been working on my site, getting the URLs to just how I want them. This is a real estate listings site, so there can be a lot of parameters in the URL.
Currently, I have the search form set to GET method, I could change this to POST if needed.
http://www.example.com/listings.php
?location=San+Jose (city or zip code)(state is hard coded in script)
<ype=for+rent (for sale or for rent)
&ptype=apartment (home, apartment, townhome, several others)
&page=4 (page number of the resutls)
&q=patio&pricemin=&pricemax=2400&bedsmin=2&bathsmin=2 (these can stay as QS variables, didn't see need the to put in the URL)
http://www.example.com/listings/San+Jose/For+Rent/Apartment/4/?q=patio&pricemin=&pricemax=2400&bedsmin=2&bathsmin=2
I figured those last parameters could stay as query string variables, instead of rewriting them in the URL, but
Location, Ltype, Ptype and Page would be good to have in the URL.
What do you think?
I also have some URLs with out all the parameters above...
http://www.example.com/listings.php?location=San+Jose<ype=for+rent&ptype=apartment
These would be nice to have as:
http://www.example.com/listings/San+Jose/For+Rent/Apartment/
I appreciate your help. I thought it would be best to get my new URLs setup correctly, then worry about 301 redirecting old ones to the new.
Thanks,
James