.htaccess规则对友好URL无效

马里奥·利马·卡瓦尔坎蒂

我正在尝试为友好的URL创建规则。我只是在Stack Overflow中寻找其他示例,但是找不到解决方案。我很确定代码是正确的,但是没有用。

例如:/index.php?p=about必须成为/about

此规则有效:

RewriteRule ^about/?$ index.php?p=about

但这(用于所有页面)不是:

RewriteRule ^([^/]*)$ /index.php?p=$1 [L]

我想使用第二条规则来处理所有页面,而不仅是关于页面。有人可以帮忙吗?

阿努巴瓦

将您的第二条规则更改为:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]

QSA (附加查询字符串)标志在添加新参数时保留了现有查询参数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章