Apache .htaccess重写规则domain.com/page/page到domain.com?p=page/page
我正在尝试设置我的Apache .htaccess重写规则domain.com/page/page到domain.com?p=page/page,apache,.htaccess,Apache,.htaccess,我正在尝试设置我的.htaccess文件。我将如何获得这个结果: 请求:domain.com/page/page 重写为:domain.com/index.php?p=page/page 我试过: RewriteRule ^(.*)$ index.php?p=$1 [L,QSA] 运气不好。在.htaccess文件中尝试以下代码: Options +FollowSymlinks -MultiViews RewriteEngine On RewriteRule ^(?!index\.php)(
.htaccess
文件。我将如何获得这个结果:
请求:domain.com/page/page
重写为:domain.com/index.php?p=page/page
我试过:
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
运气不好。在.htaccess文件中尝试以下代码:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^(?!index\.php)(.*)$ /index.php?p=$1 [L,NC,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/页面加载,但看起来很奇怪,可能样式表加载不正确?我不是很确定。通过添加一个斜杠:RewriteRule^/(.*)index.php?p=$1[L,QSA]可以加载,但页面不工作。RewriteRule^(.*)/index.php?p=$1500服务器错误。我想这是因为我添加了?p=不管是否有匹配,我都解决了这个问题。我需要两个规则: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-Z0-9\\\s-+)(/)?$index.php?p=$1 domain.com/no1将转换为domain.php=1/