homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

At a Stand Still. Rewrite Pages w/ Variables. Redirect Googles listing
Have a client need to rewrite them & redirect listings already in google

 8:33 pm on Jan 4, 2010 (gmt 0)

So I am getting this problem more and more.

We need to do 2 things.

I need to be able to come up with a formula that is idiot proof so I can take a site like:


and make it read

I know how to make the HTACCESS Process the url buy using:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /?p=$1&category=$2&style=$3 [L]

But i need to redirect it from googles index to redirect it to the SEO friendly URL.

So when a visitor comes from google it redirects to the better url.
redirect 301 /?p=products&category=hats&style=cowboy www.example.com/products/hats/cowboy.html



 9:57 pm on Jan 4, 2010 (gmt 0)

The pattern
([^/]*) allows each element to be blank, so a request for example.com///.html will unintentionally match.

Use ([^/][b]+[/b]) instead.


For your redirect, use a RewriteCond to look at the query string and a RewriteRule to do the redirect, using [R=301,L] flags. The redirect should fire only for direct client requests, not as the result of any prior rewrite action. Make sure the redirect works for index.htm and for index.html and for / without index filename.

There's lots of previous examples scattered around this forum.


 4:44 pm on Jan 5, 2010 (gmt 0)


Is there a typo in there? Are you missing a question mark following "/" and preceding "p="

The answer to this question greatly affects the solution.



 5:13 pm on Jan 5, 2010 (gmt 0)

Judging by the first example rewrite code supplied with the question, I'd say that was a typo - but the OP does need to clarify it before we can move on.


 8:11 pm on Jan 5, 2010 (gmt 0)

the problem here is not the webpage working. But when someone clicks from google I want the URL to do a 301 taking it from
www.domain.com/?p=products&category=hats&style=cowboy TO www.example.com/products/hats/cowboy.html and the user wouldn't have a clue and google would fix it's listing.(giving me a better url in it's index.)


 8:36 pm on Jan 5, 2010 (gmt 0)

To fix this problem, you must first modify all the links that appear on your pages. Then you can write a rule almost exactly opposite what you posted above to redirect the old URL requests to the new.

g1smd understands your situation quite well, based on his previous posts here and the kind of work that he does. The problem here is one of clarity and terminology rather than knowledge.

For more information, see this thread [webmasterworld.com] (and others) in our Apache Forum Library. It describes the three steps required for an end-to-end solution with the desired effect on the SERPs and your site's user experience, and the terminology is quite precise.



 9:18 pm on Jan 5, 2010 (gmt 0)

JD Thanks a bunch. here is where I am left: (it works)

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /productdetail\.php\?ID=7544&Hash=([^&]+)\ HTTP/
RewriteRule ^productdetail\.php$ http://example.com/7544/whateverIwant.html? [R=301,L]

Works like a charm. Hope that helps someone out there.

[edited by: jdMorgan at 6:43 pm (utc) on Jan. 6, 2010]
[edit reason] example.com [/edit]


 9:34 pm on Jan 5, 2010 (gmt 0)

Looks good to me. :)

However, do you also want the rule to kick in for id and Id as well as ID?

For completeness I would program it to do so, and I would probably do so whether the Hash parameter was even present or not too.

In other words, you would never be able to throw a URL request at the server with any sort of ID parameter included, that would NOT be redirected.


 4:39 pm on Jan 6, 2010 (gmt 0)

I want that for now. thanks tho.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved