0

I am using below code:

#RewriteCond %{QUERY_STRING} !(^|&)sort_field=more&limit=&p=(&|$) [NC]
#RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
#RewriteRule ^ %{REQUEST_URI}?sort_field=more&limit=&p= [L,R=301,QSA]

But it add params on all pages. I need add params only to main domain. How can I do it?

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Jenya
  • 21
  • 1
  • 1
    Please add more details here to help us understand. What do you refer to by "main domain", "pages"? Where is your condition limiting the rule to only a specific URL being requested? – arkascha Sep 19 '16 at 07:50

1 Answers1

0

First of all, these directives don't apply, because they have a hash # in front of them.


The query string (params) is added to all pages, because the pattern ^ (beginning of URL) matches all pages. If you want to match only a specific page, you must use an appropriate pattern, see Regular Expressions for details how to specify a pattern.

In your case, main domain (main page?), it would be just ^$ or ^index.html$ or similar, e.g.

RewriteRule ^$ %{REQUEST_URI}?sort_field=more&limit=&p= [L,R,QSA]

When everything works as it should, you may replace R with R=301. Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198