简体   繁体   English

.htaccess重写/重定向mod或PHP脚本

[英].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. 因此,目前我正在工作的电子商务公司正在从基于.NET的平台过渡到基于Magento PHP的网站。 The issue I'm running into is that we have 1000's of our current landing pages ranked well on search engines. 我遇到的问题是,我们目前有1000个目标网页在搜索引擎上排名良好。 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. 我无法在新平台Magento内浏览所有这些页面的301,而且我知道由于性能问题,无法将1000个静态重定向添加到.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. 所以我的问题是,是否有一种方法可以在数据库中为生成索引页面URL的变量创建重写或重定向规则。 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? 如果有的话,从性能角度来看,仅使用.htaccess文件,仅使用PHP脚本还是将两者结合使用,会更明智吗?

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 当前网址/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 / Clear_For_Life =数据库中的VendorName列
  2. Aquariums_Bowls = Subcategory Column in DB Aquariums_Bowls = DB中的子类别列
  3. AT = VendorCode Column in DB AT = DB中的VendorCode列
  4. 70_180 = PriceRange Column in DB 70_180 = DB中的PriceRange列
  5. AQAQ = CategoryId Column in DB AQAQ = DB中的CategoryId列

Desired URL to be Redirected to; 想要重定向的URL; /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. 我不相信您可以使用mod rewrite更改大小写或替换字符(“ _”至“-”)。

Why can't you 301 all these pages? 为什么您无法查看所有这些页面301? 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. 如果使用.NET访问它们,那么无论您在哪里进行路由/解析url,都应该有一行代码来进行php重定向。

我说使用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. 所以我的问题是,是否有一种方法可以在数据库中为生成索引页面URL的变量创建重写或重定向规则。 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? 如果有的话,从性能角度来看,仅使用.htaccess文件,仅使用PHP脚本还是将两者结合使用,会更明智吗?

This sounds like a job for RewriteMap . 这听起来像是RewriteMap的工作。 You'll need access to either the server or vhost config and create a map. 您需要访问服务器或vhost配置并创建映射。 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. 您可以使用此映射来调用可以从数据库中获取内容的脚本,然后确定新URI的外观。 The simplest usage of RewriteMap could be: RewriteMap的最简单用法是:

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 . /path/to/script将需要输入Clear_For_Life-Aquariums_Bowls-AT-70_180-AQAQ-ct.html ,对其进行解析,然后正确输出clear-for-life-aquariums-bowl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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