使用mod_rewrite模拟多个子目录 [英] using mod_rewrite to simulate multiple sub-directories
本文介绍了使用mod_rewrite模拟多个子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的.htaccess文件当前如下所示:
My .htaccess file currently looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9-]+)/?$ index.php?page=$1 [QSA,L]
它对于像 http://site.com/aaaaa 之类的网址很好用,但对于 http://site.com/aaaa/bbb $ _GET ['page']变量将仅包含bbb而不是aaaaa/bbb.
It works fine for urls like http://site.com/aaaaa but for urls like http://site.com/aaaa/bbb the $_GET['page'] variable will only contain bbb rather than aaaaa/bbb.
有没有办法获取page变量中的所有子目录?
Is there a way to get all of the sub-directories in the page variable?
推荐答案
在此行:
RewriteRule /?([A-Za-z0-9-]+)/?$ index.php?page=$1 [QSA,L]
您错过了^
来匹配整个字符串.另外,在您的字符串中,您要匹配URL中的/
.因此应该是:
You missed out the ^
to match the entire string. Also, in your string you want to match /
in the URL. So it should have been:
RewriteRule ^/?([A-Za-z0-9-/]+)/?$ index.php?page=$1 [QSA,L]
遗漏^
将使您获得最后一次不愉快的比赛.
Missing out ^
will get you the last ungreedy match.
这篇关于使用mod_rewrite模拟多个子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文