Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
790 views
in Technique[技术] by (71.8m points)

apache - .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:

  1. http://www.<DOMAIN>.com/catalog/brand/view?id=2

We need to utilize more friendly (seo-friendly) urls such as:

  1. http://www.<DOMAIN>.com/<BRAND>

but such that it would resolve #1 above.

Is this done in .htaccess files in the root? If so, what is the correct way to go about this?

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?

Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The apache feature you are looking for is called mod_rewrite. You should be able to google and find good resources for help here.

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.

Here's an example:

RewriteEngine On
RewriteRule (.*) 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...