开发者

htaccess / mod_rewrite for Search Engine Friendly URLs

I have a bunch of files in the web root: -

/abc-674.php

/def-643.php

etc.etc.

I want to show these when the following URL's are requested, without changing the URL in the browser: -

/products/abc-674/this_can_be_anything.php

/products/abc-674/or_this.php

both redirect to /开发者_运维百科abc-674.php, and

/products/def-643/this_can_be_anything.php

/products/def-643/or_this.php

both redirect to /def-643.php.

So, basically, the bit between products/ and the next / is the target, while anything after that can effectively be ignored.

If it matters, I've already got a little code in my .htaccess to direct all traffic to my preffered domain (with www): -

# Direct all traffic to domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] 
RewriteCond %{HTTP_HOST} !^domain$ [NC] 
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]

EDIT: To clarify - the 2nd last line in the above is because I access the site on my dev server via http://domain/ only, and so don't want that rewrite to apply for those requests. I do, however, want this new rewrite to apply to all requests.

Any help greatly appreciated!


I think, you can use the next rule in .htaccess:

RewriteRule ^products/([\d\w]+)/(.*)$ /$1.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜