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]
解决方法:
您的正则表达式有误.输入中的$不能跟在$后面,因为$表示文本的结尾.
该规则应该起作用:
RewriteEngine On
# new rule to handle example.com/blah123/sys
RewriteRule ^(\w+)/(\w+)/?$/index.php?id=$1&mode=$2 [L,QSA]
# your existing rule to handle example.com/blah123
RewriteRule ^(\w+)/?$/index.php?id=$1 [L,QSA]