Forum Moderators: phranque
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?
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
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.
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]
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]
RewriteCond %{REQUEST_URI} kw1-(.*)-kw2-(.*).htm
RewriteRule (.*) [mysite.com...] [R=301,L]
RewriteRule ^Products/(.*)/(.*)$ product-page.htm?title=$2&doc_id=$1
Thanks
# 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]
[edited by: jdMorgan at 9:05 pm (utc) on Sep. 1, 2008]