简体   繁体   English

.htacces显示名称而不是id

[英].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.

相关问题 如何在输入字段中显示占位符名称而不是值名称 - How to show placeholder name rather than the value name in the input fiels 在URL中获取产品名称,而不是ID PHP - Get product name in url rather than id php Woocommerce 在产品属性上设置的是 Term ID 而不是 Term 名称 - Woocommerce is setting the Term ID rather than the Term name on Product Attribute laravel 5显示选择表单的名称而不是它的ID(错误:试图获取非对象的属性) - Display name of select form rather than it's Id (error:Trying to get property of non-object) laravel 5 如何在Yii2中使用会话变量获取名称而不是ID - How to get name rather than id by using session variables in Yii2 我有一个简单的谱系数据库,想构建一个返回名称而不是 id 的查询 - I have a simple pedigree database and would like to structure a query that will return name rather than id 如何在 url 中使用类别名称而不是类别 ID? - How do I use the category name rather than the category id in my url? Localhost返回“未定义”而不是唯一ID - Localhost returning “Undefined” rather than the unique ID 选择所有数据而不是 id - Selection all data rather than id 使用名称而不是用户名的数据表查询 - Datatable query using name rather than username
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM