dongyong8071 2019-04-24 09:40
浏览 46
已采纳

如何查找角色的最后一个实例

I'm building this real estate script using PHP and I want the listing page url's to be like /listing/this-is-the-title-436. This url is generated in PHP and the last part of the url, after the last instance of ' - ' is the listing id. But I cannot find a way to find the last instance of a dash and use the rest as a variable in .htaccess.

Note that the title can have any amount of spaces therefore any amount of dashes but the listing id will always be at the end, after the last dash.

To summarize, I want urls like /listing/this-is-the-title-436 to redirect to /assets/inc/listing.php?listing=436 with .htaccess.

Any help would be appreciated, thanks!

  • 写回答

1条回答 默认 最新

  • douyalin0847 2019-04-24 09:48
    关注

    The easiest way is to test a numerical value at the end:

    RewriteEngine on
    RewriteRule ^listing/.+-(\d+)$ /assets/inc/listing.php?listing=$1 [L,QSA]
    

    But if you're not just using numeric values, you can also test for the absence of - in the last part:

    RewriteRule ^listing/.+?-([^-]+)$ /assets/inc/listing.php?listing=$1 [L,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备