Forums / General Questions / Using htaccess to redirect legacy links. Need help!

Using htaccess to redirect legacy links. Need help!

Views: 2,411

Results 1 to 20 of 20
22 Dec 2015, 11:40 PM
#1
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Using htaccess to redirect legacy links. Need help!

Hi,

I have a site that I monitor with Google Webmaster. I built the site like two years ago. A few weeks ago, the console began alerting me to an increase of 404 Not Found Errors. In the console, I drilled into the links to find the source. Google was claiming that many of the non-existing links were coming non-existing pages.

Further study showed that the links not being found did exist, before I switched over to ZC. And I was able to find some external websites that were linking in to my site, using the now ancient/non-working url's.

SOLUTION: I decided to build a redirect tree into the htaccess for the old sitemap.

But this seems to be creating even more problems! :(

This site, btw, uses Ceon URI and that is the only other content of the htaccess file. Here is that code:

## BEGIN CEON URI MAPPING REWRITE RULE

RewriteEngine On

# Don't rewrite any URIs ending with a file extension (ending with .[xxxxx])
RewriteCond %{REQUEST_URI} !\.[a-z]{2,5}$ [NC]
# Don't rewrite any URIs for some, popular specific file format extensions,
#   which are not covered by main file extension condition above
RewriteCond %{REQUEST_URI} !\.(mp3|mp4|h264)$ [NC]
# Don't rewrite any URIs for some specific file format extensions,
#   which are not covered by main file extension condition above
#   Uncomment the following line to apply this condition! (Remove the # at the start of the next line)
#RewriteCond %{REQUEST_URI} !\.(3gp|3g2|h261|h263|mj2|mjp2|mp4v|mpg4|m1v|m2v|m4u|f4v|m4v|3dml)$ [NC]
# Don't rewrite admin directory
RewriteCond %{REQUEST_URI} !^/admin_S2g6 [NC]
# Don't rewrite editors directory
RewriteCond %{REQUEST_URI} !^/editors/ [NC]
# Don't rewrite logs directory
RewriteCond %{REQUEST_URI} !^/logs/ [NC]
# Handle all other URIs using Zen Cart (its index.php)
RewriteRule .* index.php [QSA,L]

## END CEON URI MAPPING REWRITE RULE

There are two types of links in my legacy sitemap:

  1. straight forward links and 2) links that contain regular expressions

I can get the straight links to give a 301 instead of a 404 by simply adding this below Ceon rewrite (currently 125 lines of this re-map):

Redirect 301 /Hakko_HJ5000_Heat_Gun_1300w_Dual_Temp_RC_Skin_B /index.php
Redirect 301 /prod-HAKKO_FX_8804_Hot_Tweezer-347.aspx /Hakko_950_Hot_Tweezer_Conversion_Kit_w_Holder
Redirect 301 /cat-Extraction_Kits-76.aspx /Fume_Dust_Extraction/Extraction_Systems
Redirect 301 /cat-Flux_and_Cleaners-27.aspx /Solder_Fluxes_Chemicals/Fluxes
Redirect 301 /cat-General_Purpose_Tweezers-51.aspx /General_Purpose_Tweezers_7
Redirect 301 /pdf/DesiccantRegeneration.pdf /download/ppk_pdf/DesiccantRegeneration.pdf

The problem is... I can't figure out how to get links in the second category to be treated literally. Here are some examples:
Redirect 301 /search.aspx?advanced=1 /index.php
Redirect 301 /pdf/48950%20Drawing.pdf /PROTEKTIVE_PAK_48950_BAG_PROTECTIVE-SHIELD_MBB_4_MIL_10INx20IN_100_EA_PACK
Redirect 301 /pdf/TDS_NC%20251%20Sn62%20&%20Sn63%20Solder%20Paste.pdf /index.php
Redirect 301 /detail.aspx?ID=124 /index.php
Redirect 301 /detail.aspx?ID=75 /index.php
Redirect 301 /detail.aspx?ID=80 /index.php

Can somebody please show me how to rewrite links like the ones above, such that the legacy link will be treated literally?

And yes, I know a blank space in a file name (%20) is bad form. But that is legacy, not my doing!

22 Dec 2015, 11:53 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using htaccess to redirect legacy links. Need help!

Can somebody please show me how to rewrite links like the ones above
Do you have valid links to send then to?

Zen-Venom Get Bitten

22 Dec 2015, 11:57 PM
#3
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

Also, can somebody show me how to write a RedirectMatch?

In particular, there are a whole series of unknown pages (no way to match it up with anything!) that go something like this:
detail.aspx?ID=112
detail.aspx?ID=73
detail.aspx?ID=98
detail.aspx?ID=11

I would like to be able to send them all to the index. Here are some examples I found:
RedirectMatch 301 ^/(.).htm$ /$1.html
RedirectMatch 301 ^/200([0-9])/([^01])(.
)$ /$2$3
RedirectMatch 301 ^/category/(.)$ /$1
RedirectMatch 301 ^/(.
)/htaccesselite-ultimate-htaccess-article.html(.) /htaccess/htaccess.html
RedirectMatch 301 ^/(.
).html/1/(.) /$1.html$2
RedirectMatch 301 ^/manual/(.
)$ http://www.php.net/manual/$1
RedirectMatch 301 ^/dreamweaver/(.)$ /tools/$1
RedirectMatch 301 ^/z/(.
)$ http://static.askapache.com/$1

But I have no idea how to use any of that! :(

22 Dec 2015, 11:59 PM
#4
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

kobra:

Do you have valid links to send then to?

About 80% can be matched to a ZC page. The rest... I have no clue what they used to point to, so I'm sending those to the index.

23 Dec 2015, 12:02 AM
#5
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using htaccess to redirect legacy links. Need help!

there are a whole series of unknown pages
Do ALL of these begin with

detail.aspx?ID=

Zen-Venom Get Bitten

23 Dec 2015, 12:06 AM
#6
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

For every page that begins that way (detail.aspx?ID=), I do not have a matching page because I have no way to know what those pages were. Therefor, every page that begins that way, I was planning to send to the index.

Every single one.

23 Dec 2015, 12:07 AM
#7
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using htaccess to redirect legacy links. Need help!

Try this for these

Redirect 301 /pdf/48950%20Drawing.pdf /PROTEKTIVE_PAK_48950_BAG_PROTECTIVE-SHIELD_MBB_4_MIL_10INx20IN_100_EA_PACK

Change to use the full url for the new page

Redirect 301 /pdf/48950%20Drawing.pdf http://domain.com/PROTEKTIVE_PAK_48950_BAG_PROTECTIVE-SHIELD_MBB_4_MIL_10INx20IN_100_EA_PACK

Zen-Venom Get Bitten

23 Dec 2015, 12:12 AM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Using htaccess to redirect legacy links. Need help!

Let me try to understand this, you have a uri rewriter that can be setup to redirect any provided uri to something else on your site and you're trying to use/write htaccess rules to rewrite uris to new/existing uris that are managed by the uri rewriter? And through all this you are going to continue to use the uri rewriter. You're not trying to uninstall it or anything...

Do you have a backup of the uri_mappings table of the affected store before the mess was created/started...

I saw the equivalent post in the ceon uri mappings thread, but haven't had the time to look up the "second" part of the question to provide a full answer. I just know what I would do/try to do and yes let the software do what t does...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Dec 2015, 12:19 AM
#9
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using htaccess to redirect legacy links. Need help!

For the detail.aspx links try this

RewriteEngine On
RewriteRule ^detail.aspx([^/.]+).html$ index.php?id=$1 [L]

Zen-Venom Get Bitten

23 Dec 2015, 12:21 AM
#10
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

I tried your suggestion already, Kobra. Both ways (with and w/o full domain). The "%" seems to break it. :(

MC, I do have an old excel that has many of the origninal URLs lined up with products. And I have been able to make educated guesses to match others. Others (like those that begin with detail.aspx?ID=) are impossible to match at this point.

No, I am not going to uninstall Ceon. I considered trying to insert the uri's into the ceon mapping table, but was unsure of how to proceed (nobody responded to the post you mentioned).

Sooooo... yes, I'd like to let the software handle it. I just couldn't quite figure out how to do it. At least, in a way that would not cause me to worry that I had broken something.

And besides, using the htaccess file seems to do the trick. Since it's so straight forward, why not? Doesn't seem to slow the site down, though I know that could become a problem if it got super big.

23 Dec 2015, 12:24 AM
#11
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

kobra:

For the detail.aspx links try this

RewriteEngine On
RewriteRule ^detail.aspx([^/.]+).html$ index.php?id=$1 [L]


Kobra, referring you back to the OP... Ceon is already using RrewriteEngine. Should I skip your first line and just add your rule to the bottom of his?
23 Dec 2015, 12:30 AM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Using htaccess to redirect legacy links. Need help!

Feznizzle:

About 80% can be matched to a ZC page. The rest... I have no clue what they used to point to, so I'm sending those to the index.

If that's so and the matching location is known, it would make more sense decode the uri in advance of the ceon uri htaccess entry back to the zc standard entry and let the uri rewriter provide the new/destination address...

Before you know it you'll have written 301s pointing to other rewritten 301 uris... Ceon prevents this mess by redirectng any old uri to the current one in a single "bounce".

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Dec 2015, 12:39 AM
#13
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

mc12345678:

If that's so and the matching location is known, it would make more sense decode the uri in advance of the ceon uri htaccess entry back to the zc standard entry and let the uri rewriter provide the new/destination address...

Before you know it you'll have written 301s pointing to other rewritten 301 uris... Ceon prevents this mess by redirectng any old uri to the current one in a single "bounce".

So... you are saying that I should match and insert it into the Ceon mapping table? Not use htaccess? Or are you saying I should move my 301 redirects in the htaccess up above the Ceon rerwrite rules?

BTW, Kobra... I inserted your rule. When I tried to visit one of the links it is designed to capture, it gave me a 404.

23 Dec 2015, 2:04 AM
#14
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Using htaccess to redirect legacy links. Need help!

Feznizzle:

I tried your suggestion already, Kobra. Both ways (with and w/o full domain). The "%" seems to break it. :(

MC, I do have an old excel that has many of the origninal URLs lined up with products. And I have been able to make educated guesses to match others. Others (like those that begin with detail.aspx?ID=) are impossible to match at this point.

No, I am not going to uninstall Ceon. I considered trying to insert the uri's into the ceon mapping table, but was unsure of how to proceed (nobody responded to the post you mentioned).

Sooooo... yes, I'd like to let the software handle it. I just couldn't quite figure out how to do it. At least, in a way that would not cause me to worry that I had broken something.

And besides, using the htaccess file seems to do the trick. Since it's so straight forward, why not? Doesn't seem to slow the site down, though I know that could become a problem if it got super big.

Secret to the uri rewriting table is to know the standard ZC uri and then plug in the fields basically. Any "product" that is to be referencable from the old uri but recognized as the new one is statussed as inactive. Only one uri for a "product" is to be marked as the active one.

I thought there were examples in the documentation or at least enough information to generate equivalent uris. Just sayin'. There should also be plenty of examples inside of the existing store, and even more so if a development server/backup is setup to not use the uri rewriter you can then see exactly what the uri looks like for both sides of the uri.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Dec 2015, 2:18 AM
#15
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Using htaccess to redirect legacy links. Need help!

Feznizzle:

So... you are saying that I should match and insert it into the Ceon mapping table? Not use htaccess? Or are you saying I should move my 301 redirects in the htaccess up above the Ceon rerwrite rules?

BTW, Kobra... I inserted your rule. When I tried to visit one of the links it is designed to capture, it gave me a 404.

I'd do whatever stops the bleeding... Then end with ceon containing the rewrites and getting rid of the unnecessary htaccess rewrites that are covered already by ceon. Also it seems like that perhaps the rewrites had previously existed in the database, but after whatever work was done to the database, that the old ones were removed/new generated that basically now point to "nowhere".
Whatever, I'd do whatever can be done accurately and quickly, preferably one time and not some long drawn out process...

Does it automatically emit a 301? Still haven't looked to tell, but over the last couple of years the statement has been no it doesn't, although there is a database table field that can be populated with a redirect related code... Just don't know off hand if it is ever used or is just suckiing up database space.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

4 Jan 2016, 7:38 PM
#16
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

Feznizzle:

Also, can somebody show me how to write a RedirectMatch?

In particular, there are a whole series of unknown pages (no way to match it up with anything!) that go something like this:
detail.aspx?ID=112
detail.aspx?ID=73
detail.aspx?ID=98
detail.aspx?ID=11

I would like to be able to send them all to the index. Here are some examples I found:
RedirectMatch 301 ^/(.).htm$ /$1.html
RedirectMatch 301 ^/200([0-9])/([^01])(.
)$ /$2$3
RedirectMatch 301 ^/category/(.)$ /$1
RedirectMatch 301 ^/(.
)/htaccesselite-ultimate-htaccess-article.html(.) /htaccess/htaccess.html
RedirectMatch 301 ^/(.
).html/1/(.) /$1.html$2
RedirectMatch 301 ^/manual/(.
)$ http://www.php.net/manual/$1
RedirectMatch 301 ^/dreamweaver/(.)$ /tools/$1
RedirectMatch 301 ^/z/(.
)$ http://static.askapache.com/$1

But I have no idea how to use any of that! :(

Does anybody know how to use RedirectMatch 301 to catch links that end like this?
detail.aspx?ID=ANY NUMBER

ALTERNATIVELY

Does anybody know how to use Redirect 301 to catch the specific links?
detail.aspx**?ID=112
detail.aspx
?ID=**73

When I use a question mark or equal sign, it breaks my site. The problem is that I cannot figure out how to get the operatives ("?" and "=") to be treated literally. Does that make sense? If I could treat those dynamic links as static, then I could simply add a line for each ID# and be done with all this.

Help, please! I have been scratching my head for hours! I feel like Kobra was really close, I just can't figure it out.

4 Jan 2016, 10:18 PM
#17
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using htaccess to redirect legacy links. Need help!

This might assist it is a cheat sheet for mod_rewrite get it **HERE**

Zen-Venom Get Bitten

5 Jan 2016, 12:33 AM
#18
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

kobra:

This might assist it is a cheat sheet for mod_rewrite get it **HERE**

Awesome! I will get a ton of use out of this, even if I can't figure out the task at hand!

I will screw around with this and follow up with the results.

5 Jan 2016, 12:41 AM
#19
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

In the center of this pdf, there is a table called: "Metacharacters (must be escaped)"

Missing from it is the equals symbol (=). This may be my problem. But I swear I tried it with and w/o escaping the equal... "=" and "=".

Also, should I escape periods? Seems like if I do that, then all the other periods get viewed as meta?

Hmmmmmmmm

5 Jan 2016, 2:11 AM
#20
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: Using htaccess to redirect legacy links. Need help!

Ok, this is the best I could come up with:
Redirect 301 /detail.aspx /index.php

You can try a few:
http://smtsuppliesDOTcom/detail.aspx?ID=73
http://smtsuppliesDOTcom/?ID=73 <--becomes this, plus sends a 301

http://smtsuppliesDOTcom/detail.aspx?ID=44
http://smtsuppliesDOTcom/?ID=44 <--becomes this, plus sends a 301

http://smtsuppliesDOTcom/detail.aspx?ID=97
http://smtsuppliesDOTcom/?ID=97 <--becomes this, plus sends a 301

I really wish there was a way to kill that stinking "?ID=##"

sigh

Well, I guess I'm done. Maybe it is better to leave that little bit on there? Dunno. To the point that I don't care.