.htaccess 检测由“-”分隔的数字
.htaccess detect numbers separated by '-'
我在网上找不到任何有用的资源,所以我只是在这里问一下
我的 .htaccess 文件包含以下代码行:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^KOP/shop/(\d+)*$ KOP/shop/details.php?id= [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id= [L]
当我进入
localhost/KOP/order/1612-8077-68
I get a page not found error
但是当我进入
localhost/KOP/order/1612807768
The rewrite works, and writes out the number from $_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= [L]
RewriteRule ^KOP/order/(\d{4})-(\d{4})-(\d{2})$ KOP/order.php?id=-- [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= [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id= [L]
我在网上找不到任何有用的资源,所以我只是在这里问一下
我的 .htaccess 文件包含以下代码行:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^KOP/shop/(\d+)*$ KOP/shop/details.php?id= [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id= [L]
当我进入
localhost/KOP/order/1612-8077-68
I get a page not found error
但是当我进入
localhost/KOP/order/1612807768
The rewrite works, and writes out the number from $_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= [L]
RewriteRule ^KOP/order/(\d{4})-(\d{4})-(\d{2})$ KOP/order.php?id=-- [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= [L]
RewriteRule ^KOP/order/(\d+)*$ KOP/order.php?id= [L]