Php htaccess mod_重写中的多个变量
我想要Php htaccess mod_重写中的多个变量,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我想要rando.com/game/basic/1指向rando.com/game.php?type=basic&id=1 到目前为止,我所拥有的: #Fix Rewrite Options -Multiviews # Mod Rewrite Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
rando.com/game/basic/1
指向rando.com/game.php?type=basic&id=1
到目前为止,我所拥有的:
#Fix Rewrite
Options -Multiviews
# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^game/([^/]+)/([^\.]+)\$ /game.php?type=$1&id=$2
这不管用。我得到一个404错误
感谢您的帮助!谢谢 为什么不按照一些MVC框架的典型方式,像这样修剪和分解php中的url呢 在htaccess中重定向到just
game.php?url=$1
$url = rtrim($_GET['url'], '/'); // to prevent empty array values caused by trailing slash
$url = explode('/', $url);
您将在$url[0]中键入,在$url[1]中键入id。
如果您只接受数字和字母,您可以这样写htaccess行:
RewriteRule ^game/([a-zA-Z0-9/]+)$ /game.php?url=$1
您的规则包含
\$
,它查找的是文本$
,而不是字符串的结尾。你想要这个:
RewriteRule ^game/([^/]+)/([^\.]+)$ /game.php?type=$1&id=$2
有什么问题吗?它不起作用了,或者发生了一些“奇怪”的事情?@I正确,它不起作用了。我得到一个404错误。可能是
$
符号前面的反斜杠?试试这个:^game/([^/]+)/([^.]+)$
好主意。不知道为什么我没有想到这一点。谢谢不客气。如果您决定接受更多变量,如type=basic id=1 showstats=1或其他任何变量,它也很方便。您只需在php中继续使用$url[2],就不会回头看@htccess file=)