Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess规则对友好URL无效_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess规则对友好URL无效

.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

我正在尝试为友好URL创建一个规则。我只是在Stack Overflow中查找了其他示例,但找不到解决方案。我很确定代码是正确的,但它不起作用

例如:
/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]