htaccess :重写网址 [英] htaccess : rewrite urls
本文介绍了htaccess :重写网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮忙改写网址
http://www.site.com/index.php?cat=catname
和
http://www.site.com/index.php?id=productname
变成这样
http://www.site.com/catname
和http://www.site.com/productname
我认为它需要 php 检查页面是否是 cat 将它作为 cat 使用或者它的产品作为产品使用
i think it will require php check if the page is cat work with it as cat or its product work with it as product
推荐答案
在 .htaccess 文件中:
in .htaccess file:
RewriteEngine On
RewriteRule ^([0-9a-z-\_]+)?$ /index.php?id=$1 [L,QSA,NC]
类别/产品检查必须在 index.php...
category/product check must be done in index.php...
或者你可以添加额外的slug
Or you can add extra slug
RewriteRule ^(category)/([0-9a-z-\_]+)?$ /index.php?category=$1 [L,QSA,NC]
RewriteRule ^(product)/([0-9a-z-\_]+)?$ /index.php?product=$1 [L,QSA,NC]
但是 url 看起来像 http://site.com/category/catname
but url will look like http://site.com/category/catname
这篇关于htaccess :重写网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文