简体   繁体   English

.htaccess多变量重写

[英].htaccess multiple variable rewriting

I managed to put together .htaccess like this and it is working fine 我设法将这样的.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]

This redirects things like example.com/one to http://www.example.com/index.php?cat=one 这会将example.com/one之类的内容重定向到http://www.example.com/index.php?cat=one

However, I would like to add more functionality for my current project so that multiple variables get parsed. 但是,我想为当前项目添加更多功能,以便解析多个变量。 So for example: 例如:

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

get parsed to 得到解析

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

Also, is solution like this seo-friendly? 此外,这样的解决方案是否友好?

Add QSA flag in last rule: 在最后一条规则中添加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 (Query String Append) flag preserves existing query parameters while adding a new one. QSA (查询字符串追加)标志在添加新查询参数时保留现有查询参数。

试试这个RewriteRule ^ mydir /([0-9] +)/(。*)$ myfile.php?var1 = $ 1&var2 = $ 2 [NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM