Forum Moderators: phranque
I want to remove duplicate content:
/matematica-clasa-p-2211-c-640.html
/matematica-clasa-p-2211-c-505.html
this is the same page, the new link looks like:
/matematica-clasa-p-2211.html
the new and the old link are the result of mod rewrite, the original link look like this:
product.php?product_id=2211
Next the question, how should i make the 301 redirect to remove the links from google duplicate content:
matematica-clasa-p-SSS-c-YYY.html to matematica-clasa-p-SSS.html [L,R=301]
or
matematica-clasa-p-SSS-c-YYY.html to product.php?product_id=SSS [L,R=301]
i'm afraid that using this method, all my links in google will look like product.php?product_id=SSS and i will lose the seo urls.
Thanks, and sorry for my bad english.
RewriteRule ^matematica-clasa-p-([0-9]+)-c-[0-9]+\.html$ http://www.example.com/matematica-clasa-p-$1.html [R=301,L]
Options +FollowSymLinks
RewriteEngine on
#
Also, to get the best results, make sure that links to matematica-clasa-p-2211-c-640.html no longer appear on your Web site.
Jim
- One redirect from dynamic URL format to new URL format.
- One redirect from old hyphenated URL to new URL format.
- One rewrite from URL format to old internal dynamic filepath.
Additionally, links on your pages should link to the new URL format.
The redirects should fire off only for direct client accesses requesting those URLs.
RedirectPermanent URL-path URL
in your case:
RedirectPermanent /product.php?product_id=2211 [domain.com...]
RewriteRule ^(.*)-p-([0-9]+)-c-[0-9]+\.html$ $1-p-$2.html [R=301,L]
and its working, i get redirected to matematica-clasa-p-2211.html
You are correct i have other rules in htaccess and this poses to another question. My htaccess looks like:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ product.php?product_id=$2
RewriteRule ^(.*)-p-([0-9]+)-c-[0-9]+\.html$ $1-p-$2.html [R=301,L]
I tried with the rule above the first one, like this:
RewriteRule ^(.*)-p-([0-9]+)-c-[0-9]+\.html$ $1-p-$2.html [R=301,L]
RewriteRule ^(.*)-p-(.*).html$ product.php?product_id=$2
But the redirection is not working, can you explain why?
Thanks.
Escape literal periods in patterns as shown in my code. Requested URL-path "x.html" is matched by the pattern "^x\.html$"
Jim
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# this is the rule i have addred for my 301 redirect
RewriteRule ^(.*)-p-(.*)-c-(.*).html$ $1-p-$2.html [R=301,L]
# this is from a seo url contribution i installed
RewriteCond %{QUERY_STRING} ^options\=(.*)$
RewriteRule ^(.*)-p-(.*).html$ product.php?products_id=$2%1
RewriteRule ^(.*)-p-(.*).html$ product.php?products_id=$2&%{QUERY_STRING}
The above works, i didn't have time to study the regular expression so i can remove the ambiguous pattern. I have tested the header with [tools.seobook.com ] and i get 301 moved for all my links:
macromedia-flash-professional-p-1108-c-173.html‎
matematica-clasa-tccd-p-2211-c-505.html‎
psihoterapie-cognitivcomportamentala-psihanaliza-p-2604-c-518.html‎
and so on, all of them redirect to link like:
macromedia-flash-professional-p-1108.html‎
matematica-clasa-tccd-p-2211.html‎
psihoterapie-cognitivcomportamentala-psihanaliza-p-2604.html‎
Thank you for your help. I will look at the "RewriteCond that looks at THE_REQUEST" you suggested.
Test your existing rules with both non-www and with www requests to see why you need that.
Add [L] to the end of the rewrites.
There is one redirect missing. Check the top of the thread where I listed all the steps that you will need.
.
You have two rewrites with the same input pattern. Is that right?
The first rewrite only fires if the "options" parameter is present, and only if is the ONLY parameter present. This is due to you start and end anchoring the pattern.
The second rewrite can only fire if the "options" parameter is not present, OR, if is present but has other parameters before or after it. Is that what you want?
Be aware that a RewriteCond can only affect the single RewriteRule immediately following it.
RewriteRule ^matematica-clasa-p-([0-9]+)-c-[0-9]+\.html$ http://www.example.com/matematica-clasa-p-$1.html [R=301,L]
But why should i redirect from old hyphenated when i have this rule?
RewriteRule ^(.*)-p-([0-9]+)-c-[0-9]+\.html$ http://www.example.com/$1-p-$2.html [R=301,L]
The problem is that i have a few hundreds links like:
text-text-text-p-([0-9]+)-c-[0-9]+\.html$
About the two rules under the rewritecond i didn't write them, they came with a contribution that is working alright.
Thanks.
I have looked into my scripts and the contribution and there is no option attribute used. So this looks like this now without any rewritecond:
RewriteRule ^(.*)-p-(.*).html$ product.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING} [L]