gpt4 book ai didi

php - .htaccess 多变量重写

转载 作者:搜寻专家 更新时间:2023-10-31 21:35:51 27 4
gpt4 key购买 nike

我设法像这样将 .htaccess 放在一起并且工作正常

RewriteRule ^$ /splash [L,R=301]        
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.examle.com/$1 [R=301,QSA,L]
RewriteRule ^([A-Za-z0-9-]+)?$ /index.php?cat=$1 [L]

这会将诸如 example.com/one 之类的内容重定向到 http://www.example.com/index.php?cat=one

但是,我想为我当前的项目添加更多功能,以便解析多个变量。例如:

example.com/category-one?another_variable=some_data&even_more=more_data, etc... 

解析为

http://www.example.com/index.php?cat=category-one&another_variable=some_data&even_more=more_data

还有,像这样的解决方案对 seo 友好吗?

最佳答案

在最后一条规则中添加QSA标志:

RewriteRule ^$ /splash [L,R=301]

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^([a-z0-9-]+)/?$ /index.php?cat=$1 [L,NC,QSA]
  • QSA(查询字符串追加)标志在添加新参数时保留现有查询参数。

关于php - .htaccess 多变量重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19995308/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com