我正在尝试设置我的.htaccess
文件。我该如何得到这个结果呢?
请求:domain.com/page/page
改写为:domain.com/index.php?p=page/page
我试过:
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
好的,我算出来了。我需要两条规则:
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=$1
domain.com/no1/会翻译成domain.com/index.php?p=no1/<——不理解结束斜杠
这个解决方案的唯一问题是它只有两个虚拟dirs深度,但这是我所需要的,它很好。这是我第一次使用。htaccess,所以我很抱歉我的理解不够。
在.htaccess文件中试试下面的代码:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^(?!index.php)(.*)$ /index.php?p=$1 [L,NC,QSA]
负向前看将避免这里的无限循环。