3

我设法像这样将 .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 友好吗?

4

2 回答 2

1

在最后一条规则中添加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) 标志在添加新参数时保留现有的查询参数。
于 2013-11-15T07:09:01.040 回答
0

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

于 2013-11-15T07:10:36.860 回答