.htaccess规则对友好URL无效
我正在尝试为友好URL创建一个规则。我只是在Stack Overflow中查找了其他示例,但找不到解决方案。我很确定代码是正确的,但它不起作用 例如:.htaccess规则对友好URL无效,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我正在尝试为友好URL创建一个规则。我只是在Stack Overflow中查找了其他示例,但找不到解决方案。我很确定代码是正确的,但它不起作用 例如:/index.php?p=about必须变成/about 这条规则正在发挥作用: RewriteRule ^about/?$ index.php?p=about 但这个(用于所有页面)不是: 我想使用第二条规则,处理所有页面,而不仅仅是关于页面。有人可以帮忙吗?将您的第二条规则更改为: # If the request is not for a
/index.php?p=about
必须变成/about
这条规则正在发挥作用:
RewriteRule ^about/?$ index.php?p=about
但这个(用于所有页面)不是:
我想使用第二条规则,处理所有页面,而不仅仅是关于页面。有人可以帮忙吗?将您的第二条规则更改为:
# 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
(查询字符串附加)标志在添加新的查询参数时保留现有的查询参数。噢,它工作起来很有魅力!非常感谢你。顺便说一句,我不知道QSA标志。
# 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]