我正在尝试设置我的.htaccess文件。我该如何获得这样的结果:
请求:domain.com/page/page
重写到:domain.com/index.php?p=page/page
我试过了:
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]不走运。
发布于 2011-07-07 02:27:04
好吧,我算出来了。我需要两条规则:
RewriteRule ^([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9_\\s-]+)/([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1/$2我的php脚本不喜欢它,因为
RewriteRule ^([a-zA-Z0-9_\\s-]+)(/)?$ index.php?p=$1domain.com/no1/会转换为domain.com/index.php吗?p=no1/<-我不理解末尾斜杠
这个解决方案的唯一问题是它只有两个虚拟目录深度,但这就是我所需要的,它是好的。这是我第一次使用.htaccess,所以我很抱歉我缺乏理解。
发布于 2011-07-05 07:56:38
在您的.htaccess文件中尝试以下代码:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^(?!index\.php)(.*)$ /index.php?p=$1 [L,NC,QSA]负向先行将避免这里的无限循环。
https://stackoverflow.com/questions/6576731
复制相似问题