.htaccess 和 seo-friendly urls [英] .htaccess and seo-friendly urls
问题描述
我们现在有一个电子商务网站,其中包含一系列品牌.品牌页面带有如下网址:
We have an ecommerce site right now that carries a range of brands. The brand pages carry urls as follows:
http://www.
.com/catalog/brand/view?id=2
我们需要使用更友好(seo-friendly)的网址,例如:
We need to utilize more friendly (seo-friendly) urls such as:
http://www.
.com/
但是这样就可以解决上面的#1.
but such that it would resolve #1 above.
这是在根目录的 .htaccess 文件中完成的吗?如果是这样,解决此问题的正确方法是什么?
Is this done in .htaccess files in the root? If so, what is the correct way to go about this?
请记住,URL#1 是合法地址,但我们希望使用 URL#2 格式进行链接.它不是 301 类型的重定向,是吗?除非我误解了它或其他什么,否则这更永久",不是吗?
Keep in mind URL#1 is the legitimate address, but we want to utilize the URL#2 format for linking. It's not a 301 type redirect is it? That's more "permanent" unless I misunderstood it or something, no?
非常感谢.
推荐答案
您正在寻找的 apache 功能称为 mod_rewrite
.您应该可以在此处 google 并找到良好的帮助资源.
The apache feature you are looking for is called mod_rewrite
. You should be able to google and find good resources for help here.
基本思想是您将指定一个正则表达式匹配,然后指定一个替换模式.可以设置做301重定向,但默认是不重定向用户,只访问重写后的url.
The basic idea is you'll specify a regular expression matching and then a replacement pattern. You can set it to do a 301 redirect, but the default is to not redirect the user, just access the re-written url.
这是一个例子:
RewriteEngine On
RewriteRule (.*) index.php
RewriteRule 表示将任何匹配的 url(.*) 重写为 index.php.这对于大多数文件并不是特别有用.我相信你会有很多例子,因为这是一个常见问题.
The RewriteRule says to rewrite any matching url(.*) to index.php. This is not particularly useful for most files. I'm sure you'll have plenty of examples as this is a common problem.
这篇关于.htaccess 和 seo-friendly urls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!