【发布时间】:2013-12-15 03:48:11
【问题描述】:
Mod 在这里重写新手。我想在 URL 中传递两个 URL 参数,但格式更友好。如果用户通过“example.com/blah123/sys”,我应该能够提取 MySQL 记录“blah123”和模式类型“sys”,在这种情况下。示例如下:
网址:
example.com/blah123/sys
在 .htaccess 中,我有:
RewriteEngine On
RewriteRule ^([^/.]+)/?$ index.php?id=$1
如果传递的 URL 是“example.com/blah123”,而不是“example.com/blah123/sys”,则上述方法有效。
我尝试了以下方法,但它不起作用:
RewriteEngine On
RewriteRule ^([^/.]+)/?$/?$ index.php?id=$1?mode=$1
我需要提取第二个参数中传递的“模式”类型。因此,如果用户输入“example.com/blah123/sys”,我应该能够从 URL 中获取值“sys”。我怎样才能做到这一点?我想使用 PHP、MySql、.htacess。
更新: 我当前的 .htaccess:
# Use PHP 5.3
AddType application/x-httpd-php53 .php
RewriteEngine On
#RewriteRule ^([^/.]+)/?$ index.php?id=$1
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?id=$1&mode=$2 [L,QSA]
【问题讨论】:
标签: php regex apache .htaccess mod-rewrite