apache - .htaccess 检测由“-”分隔的数字
问题描述
我在网上找不到任何有用的资源,所以我只是在这里问
我有我的 .htaccess 文件,其中包含以下代码行:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^KOP/shop/(\d+)*$ KOP/shop/details.php?id=$1 [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id=$1 [L]
当我输入
localhost/KOP/order/1612-8077-68 时
,出现找不到页面错误
但是当我输入
localhost/KOP/order/1612807768
重写工作,并从 $_GET 中写出数字
我想知道我应该在我的代码中改变什么,让它用数字之间的破折号重写。我的 .htaccess 文件中有一行告诉 apache 只重定向数字吗?
解决方案
根据您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^KOP/shop/(\d{4})-(\d{4})-(\d{2})$ KOP/shop/details.php?id=$1$2$3 [L]
RewriteRule ^KOP/order/(\d{4})-(\d{4})-(\d{2})$ KOP/order.php?id=$1-$2-$3 [L]
// Remove the dashes to get only the numbers ↑
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^KOP/shop/(\d+)*$ KOP/shop/details.php?id=$1 [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id=$1 [L]
推荐阅读
- excel - Excel crash after Copy and paste Chart image
- c++ - Cleaning a data file to be read as only numbers in C++
- python - Windows 10 上的 PsychoPy 无头
- android - How to add new EditText below an object and move the button below it?
- python - How can I configure MYSQL DB to accept NULL for primary key in the INSERT statement and then generate unique primary key
- mongodb - 如何创建在 Google Cloud Platform 中创建的 MongoDB 用户?
- angular - Deploying Angular Component Library to Github Pages Only absolute URLs are supported
- lua - 如何不将项目添加到另一个表中?
- sql - How to extract values from a XML column in SQL and insert into new columns?
- python - defaultdict(list, {}) 或 dict({}) 做什么?