简体   繁体   中英

.htaccess Rewrite/Redirect mod or PHP script

So currently E-commerce company I'm working for is in transition from an .NET based platform to the Magento PHP based site. The issue I'm running into is that we have 1000's of our current landing pages ranked well on search engines. There's no way for me to 301 all of these pages within the new platform - Magento, and I know I can't add 1000's of static redirects to the .htaccess file because of performance issues.

So my question is this, Is there a way to create rewrite or redirect rules for variables within our DB that generate the indexed pages URL's. If there is, performance wise would it be smarter to do this solely with the .htaccess file, just PHP Scripts or a combination of both?

Here's a sample of one of our current URLs and sample of what we'd like it to be redirected to:

Current URL /Clear_For_Life-Aquariums_Bowls-AT-70_180-AQAQ-ct.html

Here's a breakdown of the data we use to generate the rewrite;

  1. /Clear_For_Life = VendorName Column in DB
  2. Aquariums_Bowls = Subcategory Column in DB
  3. AT = VendorCode Column in DB
  4. 70_180 = PriceRange Column in DB
  5. AQAQ = CategoryId Column in DB

Desired URL to be Redirected to; /clear-for-life-aquariums-bowl

Any help or advice here would be greatly appreciated.

I don't believe you can change case or replace characters ('_' to '-') using mod rewrite.

Why can't you 301 all these pages? If they are being accessed with .NET then where ever you do the routing / parse the url there should be a line of code to do the php redirect.

我说使用htaccess,并编写一个简单的实用程序从301详细信息列表中生成上述htaccess文件。

So my question is this, Is there a way to create rewrite or redirect rules for variables within our DB that generate the indexed pages URL's. If there is, performance wise would it be smarter to do this solely with the .htaccess file, just PHP Scripts or a combination of both?

This sounds like a job for RewriteMap . You'll need access to either the server or vhost config and create a map. You can use this mapping to call a script that can fetch something from your DB, then decide what the new URI needs to look like. The simplest usage of RewriteMap could be:

RewriteMap remap prg:/path/to/script

And later you can simply do:

RewriteRule ^(.*)$ /${remap:$1|$1} [L]

The /path/to/script would need to take an input like Clear_For_Life-Aquariums_Bowls-AT-70_180-AQAQ-ct.html , parse it, and correctly output clear-for-life-aquariums-bowl .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM