Forum Moderators: phranque

Message Too Old, No Replies

301 redirect from dynamic to static

externally it works fine, but internally...

         

tanx

10:08 am on May 27, 2007 (gmt 0)

10+ Year Member



Hi webmasters

I know this topic has been covered before, so please forgive me for reposting - I've been doing lots of searching on webmasterworld for a solution to my rewrite-problem, but I haven't found the holy grail yet! I knitted some code together to externally redirect dynamic to static:

'RewriteRule widget/number(.*)/ widget.php?number=$1'

jdMorgan's article www.webmasterworld.com/forum92/6079.htm also shows how redirects should be directed internally - but alas, my poor coding-skills forbid me from making a decent internal redirect. I want requests for the following dynamic url to automatically redirect to the static url below:

www.mywebsite.com/widget.php?number=$1
www.mywebsite.com/widget/number123/

Thanks for your help!

Best
Tanx

jdMorgan

2:52 pm on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no such thing as an "internal redirect," so I'm not sure you understood the article.

Perhaps you can post specific questions about points you don't understand after reviewing it?

Jim

tanx

3:17 pm on May 27, 2007 (gmt 0)

10+ Year Member



Hi jd, well, you're probably right - there are most likely some paragraphs of the article that I've misunderstood - I'm by no means fully versed in apache :D
I think I didn't explain myself too accurately in my first post - what I meant was that I want browser requests for the dynamic url www.mywebsite.com/widget.php?number=$1 permanently redirected to www.mywebsite.com/widget/number123/ - if I understand you correctly I should use the following formula:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?product=([^&]+)&color=([^&]+)&size=([^&]+)&texture=([^&]+)&maker=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://example.com/product/%1/%2/%3/%4/%5? [R=301,L]

I've tried and tried, but to no avail I'm afraid - can you help? - I'm sorry for bugging you! :S

Btw. this refers to your bit about external (not internal, as I erroneously wrote) redirection

All the best,
Tanx

jdMorgan

4:02 pm on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless I'm missing something, it's a simple problem of substituting your URL-path and query string pieces for those in the example.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /widget\.php\?number=([^&]+)\ HTTP/
RewriteRule ^widget\.php$ http://example.com/widget/number%1/? [R=301,L]

That should get you close enough to work it out with a bit of effort. But don't use this until you fully understand it.

This is the third of three steps for using search-engine-friendly URLs, as described in the thread you cited. Be sure you've got the other two pieces in place first; Internally rewrite the friendly URLs to your script, and then change the links on your pages to use the friendly URLs. Only then is this third step useful (and safe).

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

g1smd

4:49 pm on May 27, 2007 (gmt 0)

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



Lets be sure you have the terminology right here.

An Internal Rewrite is where the link says, and the user requests, /aaaa.html and the server silently fetches the content from the file bbbb.html and sends it with a "200 OK" response. The user does not "see" the bbbb.html URL at all.

An External Redirect is where the link says, and the user requests, /bbbb.html and then the server responds with a "301 Moved" response and the URL of where the information actually resides. The browser then makes a new request, this time for aaaa.html and that information is then returned with a "200 OK" response code.

tanx

7:40 pm on May 27, 2007 (gmt 0)

10+ Year Member



I already did the two first steps you suggested - with tentative success (I haven't noticed any ill side effects yet - fingers crossed)
Your code for the third step works perfectly - thank you! :)