Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

My Web Guy told me that this cannot be programatically fixed.

I know we can fix it using mod-rewrite it

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

Junior Member

5+ Year Member

joined:Aug 25, 2008
votes: 0

I have a webpage that is SEO Friendly being


But when we goto page 2 and 3 it reads.


but I want it when I goto page 1 to read the SEO Friendly URL:

I tried using:
redirect 301 /?p=$1&section=$2&category=$3&recnum=$4 http://www.example.com/products/Promo/Gear_Products.html

but it does not work.

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

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 28, 2002
votes: 2

Unfortunately, this is very common with various shopping carts and CMS platforms, and it is NOT easily fixable.

Can it be fixed? Yep, but it will require modifying the core code of whatever backend platform you are using.

The 301 won't work as that won't affect the code being generated by your backend software, you'll need to change the way the software generates those URL's, which as mentioned, not an easy task.

7:39 pm on Jan 5, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 25, 2008
votes: 0

Actually I I have the site working fine with all friendly URLS and Rewrite in effect. The problem is I need to have all of the URLS that are in google to be updated. So here is the problem and you can understand what Im saying as I say it.

If I type in site:example.com into google there will be listings with the friendly and the unfriendly URLS. In them I do not want to have duplicate issues.

So I need to have the rewrite condition set to take the URL with the variables in and and make it SEO friendly.

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

You won't have duplicate-content issues unless your site continues to link to these old "unfriendly" URLs. If you don't link to them from your own site, they will fade away and disappear from the SERPs, given time, and they won't be 'counted against you' as duplicates.

You can also use the on-page HTML 'canonical' link tag to help this happen faster.

If you wish to proceed with a programmatic solution, you won't be able to fix this problem without access to your database, because mod_rewrite has no way to find the new "friendly" URL given only the old "unfriendly" one -- It has no way to "create" the "Products_Gear" part of the friendly URL given only the information in the unfriendly URL's query string. The database access is needed to get this information. This access can be accomplished in two ways:

1) If a request for an "unfriendly" URL is received from a client, call a new script (or a modified version of your existing script) which will look up the product-name-title as in "Gear_Products" by using the p=, c=, and recnum= parameters as needed, and then generate a 301-Moved Permanently redirect to the new canonical URL.
2) If you have server config access, define a RewriteMap which invokes a script to open the database, do the lookup as above, and then return the canonical URL to mod_rewrite, which can then generate the 301 to the canonical URL. This is fairly-easily done in PERL, as long as you remember that there is only one copy of this script, it is started when the server is re-booted, and it must not be allowed to 'die' under *any* circumstances (otherwise you will need to re-boot the server every time a db call fails -- Not good).

The tricky part I've mentioned twice is that the redirect must only be done if the "unfriendly" URL is requested as a URL by the client, and not if it is internally-requested as a filepath as a result of the internal rewrite you are likely already using to map "friendly" URLs to the "unfriendly" script-filepath-plus-query-string. This can be done simply by adding a RewriteCond to the redirect rule which checks the server variable %{THE_REQUEST} to make sure that this request is from a client directly-requesting the "unfriendly" URL. In your case, it would take one of the following the forms, depending on how you choose to implement the scripted lookup and redirect (as previously described).

# Rewrite direct client requests for unfriendly URLs to script for disposition,
# adding a query parameter to indicate that a redirect is required
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /\?p=[A-Z][a-z]*&section=[A-Z][a-z]*&category=[A-Z][a-z]*+&recnum=[0-9]+\ HTTP/
RewriteRule ^$ /path-to-redirect-script.php?redirect-this=yes [QSA,L]


# Redirect direct client requests for unfriendly URLs to the corresponding
# canonical URLs using RewriteMap script defined in the server config file
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /\?p=([A-Z][a-z]*)&section=([A-Z][a-z]*)&category=([A-Z][a-z]*)+&recnum=([0-9]+)\ HTTP/
RewriteRule ^$ /http://www.example.com/${RewriteMapName:%1-%2-%3-%4} [R=301,L]

There are many more details, and the above two code snippets are only examples to get you started.


10:06 pm on Jan 5, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
votes: 0

There's often an additional problem to be solved here.

It is simply that for page 2 you need the '2' to be within the URL, but for page 1 most solutions allow the '1' to be optional - and that is yet another duplicate content problem to be solved.

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

Junior Member

5+ Year Member

joined:Aug 25, 2008
votes: 0

Im fine with 2,3,4,5,6,7, showing. I just want the Page 1. to show the URL friendly one.