php - HTACCESS URL 重写
问题描述
请问如何使用 .htaccess 检索以下 URL 的 abc123 部分?
https://a.com/product/abc123
我需要使用 abc123 部分来创建查询。通常,我知道这可以通过以下方式实现:
https://a.com/product/?key=abc123
并像这样使用 $_GET 获取 abc123 部分:
$product_key = $_GET['key'];
但我更喜欢 htaccess 方法,我需要帮助。
解决方案
在您的 .htaccess 文件中放置并使用此规则
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?product/(.*?)/?$ /index.php?key=$1 [L]
推荐阅读
- javascript - JavaScript:垂直遍历多维数组
- python-3.x - 没有安装候选时如何将 libpcre3-dev 添加到 docker 映像 python3.8-slim
- javascript - 单击单词以选择并作为答案提交
- apache-kafka - 我如何像关系数据库一样使用 Kafka
- django - 自动将 django 中的 user_id 和 date 字段更新到数据库中
- azure - Azure Web App 和 Azure SQL Server 的 VNet 集成
- python - ValueError:不允许负尺寸错误?
- flutter - Flutter:是否有可能将按钮值发送到文本字段?
- node.js - 谷歌工作表 api nodejs
- android - 如何在颤振上创建这样的卡片?