Forum Moderators: phranque

Message Too Old, No Replies

Redirect a rewritten dynamic page to another

title-widget-id.htm -> title-id.htm

         

rowtc2

7:21 am on Aug 28, 2008 (gmt 0)

10+ Year Member



I want to redirect 301 a dinamic php page, to eliminate keyword1 and keyword2 words from the url.I want to keep just the title and id of the product from database.

Actual htacces rule:
RewriteRule ^kw1-(.*)-kw2-(.*).htm productpage.htm?title=$1&doc_id=$2
Actual url: www.site.com/kw1-title-kw2-id.htm

I need to make it just with the title and id of the product,without kw1 and kw2 .
New url needed: www.site.com/title-1.htm

Could you help me with a suggestion for htacces code? The old rule code must be deleted or remain in htacces?

jdMorgan

4:03 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to "change the URL" as seen by the visitor, then you must change the URLs used in links on all of your pages -- Those links *define* the URL.

Having done that, your internal rewrite from the static URL to the dynamic script filepath is simplified.

A third optional step is to redirect any published URLs that point directly to your script, 301-redirecting them to the static URLs.

See this thread [webmasterworld.com] in our forum library for details.

Jim

rowtc2

6:13 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Thanks Jim,
i have done this:

Old situation:

- actual url:
[mysite.com...]
[mysite.com...]
....

- link who define the url
[mysite.com...]

- htaccess rule:
RewriteRule ^kw1-(.*)-kw2-(.*).htm productpage.htm?title=$1&doc_id=$2

New situation:

- desired url
[mysite.com...] or [mysite.com...]

-link who define the url
[mysite.com...]

- htaccess file (old rule is still present):
RewriteRule ^kw1-(.*)-kw2-(.*).htm productpage.htm?title=$1&doc_id=$2
RewriteRule ^Products/(.*)-(.*).htm productpage.htm?title=$1&doc_id=$2 (if i dont put Product/ gives me 404)
Redirect permanent /kw1-(.*)-kw2-(.*).htm [mysite.com...]

I have reading the last line will redirect a page:is working for a defined generated page (if i replace (.*) with names in htacces is working 301) , but it doesn't work in dynamic mode. I must redirect old url's for Google , to see old url's are moved to new url's. I need to eliminate kw1 and kw2 who are looking spammy and i have some traffic problems.
Any help is appreciated.

jdMorgan

6:28 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, please read the thread I cited above, and then ask specific questions back here.

The exact answer to your question is in that thread.

Jim

rowtc2

7:57 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



I read indicated post and i will read again,but looks to do like you described in that thread.
I have deleted old rule and i write this:

RewriteRule ^Products/([^/]+)-([^/]+).htm?$ /product-page.htm?title=$1&doc_id=$2 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product-page\.htm\?title=([^&]+)&doc_id=([^&]+)\ HTTP/
RewriteRule ^product-page\.htm$ http://www.example.com/Products/%1-%2.htm? [R=301,L]

The new url is www.mysite.com/Products/John-1.htm and is working good. But when i copy the old url in browser and hit enter gives me a 404 (is redirected to my 404 custom page). When the server must return product-page.htm requested in other structure then rewrite rule gives me 404.

In the last line should be defined in some way the old rewritten url at the beginning?
product-page\.htm$ is a general term and if the server doesn't recognise the page who is requested ? (sorry for my English).

[edited by: jdMorgan at 10:05 pm (utc) on Aug. 28, 2008]
[edit reason] example.com [/edit]

g1smd

9:26 pm on Aug 28, 2008 (gmt 0)

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



Redirects should be first (things with R=301 in them).

Rewrites should be last.

jdMorgan

10:04 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few minor errors in there. I'd suggest:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product-page\.htm\?title=([^&]+)&doc_id=([^&\ ]+)\ HTTP/
RewriteRule ^product-page\.htm$ http://www.example.com/Products/%1-%2.htm? [R=301,L]
#
RewriteRule ^Products/([^\-]+)-([^.]+)\.htm$ /product-page.htm?title=$1&doc_id=$2 [L]

[added] Be sure to completely flush your browser cache before testing any new code. [/added]

Jim

[edited by: jdMorgan at 10:06 pm (utc) on Aug. 28, 2008]

rowtc2

9:40 am on Aug 31, 2008 (gmt 0)

10+ Year Member



It didnt work,because old urls gives me 404.
But was working with this:

RewriteCond %{REQUEST_URI} kw1-(.*)-kw2-(.*).htm
RewriteRule (.*) [mysite.com...] [R=301,L]
RewriteRule ^Products/(.*)/(.*)$ product-page.htm?title=$2&doc_id=$1

Thanks

rowtc2

9:42 am on Aug 31, 2008 (gmt 0)

10+ Year Member



[edited]

jdMorgan

9:05 pm on Sep 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps you simply need to add a rule to redirect the old style URL to the new style static URL, so that the new-style-URL-to-script rewrite will then handle it. Something like this:

# Externally redirect direct client requests for dynamic URLs
# (now used only as internal filepaths) to new-style static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /product-page\.htm\?title=([^&]+)&doc_id=([^&\ ]+)\ HTTP/
RewriteRule ^product-page\.htm$ http://www.example.com/Products/%1-%2.htm? [R=301,L]
#
# Externally redirect requests for old-style static URLs to new-style static URLs
RewriteRule ^(Products/)?kw1-([^\-]+)-kw2-([^.]+)\.htm http://www.example.com/Products/$2/$3? [R=301,L]
#
# Internally rewrite new-style static URLs to script filepath
RewriteRule ^Products/([^\-]+)-([^.]+)\.htm$ /product-page.htm?title=$1&doc_id=$2 [L]

Jim

[edited by: jdMorgan at 9:05 pm (utc) on Sep. 1, 2008]