[英].htacces to show name rather than id
I have a table containing catname(catename) and catid(23). 我有一个包含catname(catename)和catid(23)的表。 right now in url I am showing catid=23.
现在在url我显示catid = 23。 I have defined a rewrite rule which show example.com/13 in url for this : example.com?catid=13 Is it possible to achieve following
我已经定义了一个重写规则,在url中显示example.com/13:example.com?catid = 13是否有可能实现以下
In url : example.com/catename Actual page it is showing : example.com?catid=13 在url中:example.com/catename实际页面显示为:example.com?catid=13
First you want to send the category name also within the URL. 首先,您还要在URL中发送类别名称。
Then use, in .htaccess
: 然后在
.htaccess
使用:
RewriteRule ^(.*)-c-(.*).html$ product_info.php?catid=$2%1
It work for me. 它对我有用。
Another Solution 另一种方案
If you want to show only catname
, not catid
, then you want to create a new field in the table with an unique key. 如果只想显示
catname
而不是catid
,那么您想在表中使用唯一键创建一个新字段。 Then save alias name of the category here that you want to show in the URL. 然后在此处保存要在URL中显示的类别的别名。
This is possible. 这个有可能。 You'd need to ensure that
catname
was unique and if it is not, you'd need to add an additional field, permalink/uniqid, to contained a unique and friendly URL alias. 您需要确保
catname
是唯一的,如果不是,则需要添加一个额外的字段permalink / uniqid,以包含唯一且友好的URL别名。
RewriteRule ^/(\s+)$ ./index.php?catname=$1
You'd need to then check for catname
in your PHP file and handle accordingly. 然后,您需要在PHP文件中检查
catname
并进行相应处理。
The best thing to do will be to use urls such as example.com/13-catname if your category name is not unique. 如果您的类别名称不是唯一的,最好的办法是使用example.com/13-catname等网址。 Change your rewrite rule to extract the ID and pass it to the PHP script.
更改您的重写规则以提取ID并将其传递给PHP脚本。
thanks for the suggestion. 谢谢你的建议。 Now I got it.
现在我懂了。 since catname is not unique two page can have same url, for this I have to ensure that it should be unique.
由于catname不是唯一的,所以两个页面可以具有相同的url,为此,我必须确保它应该唯一。 I can add Id in front to make it unique.
我可以在前面添加Id以使其独特。 From such name i can acheive this.
从这样的名字我可以做到这一点。 thanks a lot.
非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.