<p>One way you can avoid this is by making a small change to the htaccess rules for removing index.php from Craft URLs. You can remove the query string from <code>RewriteRule (.+) index.php?p=$1 [QSA,L]</code> and replace it with <code>/$1</code></p>

<p>So the full set of rules to remove index.php would be</p>

<pre><code># Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php/$1 [QSA,L]
</code></pre>

<p>This seems to work fine in my test and prevents the query string from being appended to the URL when using <code>Redirect 301</code> in htaccess.</p>

CC BY-SA 3.0
2014-07-11T16:34:44.927Z
In my tests, this seems to work! However, what are the possible side-effects of removing the ?p=
lealea
CC BY-SA 3.0
2014-07-11T16:40:36.147Z
The only side effect of that change is it won’t work on servers that don’t support PATH_INFO. If it looks like it’s working for you, then great!
Brandon Kelly
CC BY-SA 3.0
2014-07-11T16:30:23.017Z
2014-07-11T16:30:23.017Z
Alex Kendrick
<p>What happens if you add a <code>?</code> to the rule:</p>

<pre><code>RewriteRule ^blog/category?$ /blog/archive [R=301,L,NE]
</code></pre>

CC BY-SA 3.0
2014-07-11T16:44:06.007Z
Still gave me a 404
lealea
CC BY-SA 3.0
2014-07-11T17:40:54.650Z
When you put a `?` right after another character in a regular expression, you’re just saying that whatever came before it is optional. So that pattern would match both “blog/category” and “blog/categor”. (Usually it’s good idea to put a `?` right before a trailing slash, so you’re matching both “blog/category/” and “blog/category”.)
Brandon Kelly
CC BY-SA 3.0
2016-05-25T09:11:04.770Z
s/right before a trailing slash/right after a trailing slash/
Olaf Dietsche
CC BY-SA 3.0
2014-07-11T16:25:48.343Z
2014-07-11T17:22:01.850Z
2014-07-11T17:22:01.850Z
Jessica D'Amico
<p>If you need to remove these from search results, you may find this helpful: <a href="https://stackoverflow.com/questions/14071671/remove-query-string-from-end-of-url-url-using-htaccess">Remove Query Strings from URLs</a></p>

CC BY-SA 3.0
2016-03-29T20:39:19.957Z
2016-03-29T20:39:19.957Z
2017-05-23T12:38:53.957Z
Caroline from Aquarian
<p>The issue here is that your <code>Redirect</code> directive is conflicting with Craft’s index.php-hiding <code>RewriteRule</code> directive. <em>(<code>Redirect</code> is a <a href="http://httpd.apache.org/docs/2.2/mod/mod_alias.html">mod_alias</a> directive and <code>RewriteRule</code> is a <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html">mod_rewrite</a> directive. They’re two separate modules that can be used for the same thing, but lead to unexpected consequences when used together.)</em></p>

<p>To fix this, use a <code>RewriteRule</code> directive for your own custom redirects as well, rather than <code>Redirect</code>.</p>

<pre><code>RewriteRule ^blog/category(/.*)?$ /blog/archive$1 [R=301,L]
</code></pre>

<p>Make sure that you place that <em><strong>before</strong></em> Craft’s redirect.</p>

CC BY-SA 3.0
2014-07-11T16:15:39.523Z
That gives me a 404 :(
lealea
CC BY-SA 3.0
2014-07-11T16:17:07.793Z
Is this meant to be in ADDITION instead of replacement? If it's in addition, I added the original Redirect above and then the one you have up there with the rewrite it still appends the URL
lealea
CC BY-SA 3.0
2014-07-11T16:41:16.960Z
Should be a replacement. Old code out. This is what I used on an EE project where I was having this problem.
Anna_MediaGirl
CC BY-SA 3.0
2014-07-11T16:46:39.290Z
Make sure you place that _before_ Craft’s redirect.
Brandon Kelly
CC BY-SA 3.0
2014-07-11T17:16:49.413Z
Yes, mine is right after "RewriteEngine on". Adding that to my answer.
Anna_MediaGirl
CC BY-SA 3.0
2014-07-11T17:51:51.250Z
Noticed that this works if it's just /blog/category — it will redirect to /blog/archive. However, I need it to redirect when something is after it. e.g. /blog/category/category-name to /blog/archive/category-name
lealea
CC BY-SA 3.0
2014-07-11T18:02:35.220Z
@lealea Ah, didn’t realize that’s what you wanted. Just updated the code.
Brandon Kelly
CC BY-SA 3.0
2014-07-11T16:11:46.717Z
2014-07-11T18:02:15.237Z
2014-07-11T18:02:15.237Z
Anna_MediaGirl
<p>Whether I'm using the Reroute plugin or plugging it in .htaccess, changing the path elsewhere appends the query in the end. How can I remove?</p>

<pre><code>Redirect 301 /blog/category /blog/archive
</code></pre>

<p>Is the line I have in my .htaccess</p>

<p>So if I go to:</p>

<p><a href="http://domain.com/blog/category/category-name">http://domain.com/blog/category/category-name</a></p>

<p>it takes me to:</p>

<p><a href="http://domain.com/blog/archive/category-name?p=blog/category/category-name">http://domain.com/blog/archive/category-name?p=blog/category/category-name</a></p>

<p>What's going on here? </p>

<url><redirect><redirection>
301 Redirects Appends ?p=original/url/path - how can I remove?
# 301 Redirects Appends ?p=original/url/path - how can I remove?

(Asked by: username_0 on 2014-07-11)

Whether I'm using the Reroute plugin or plugging it in .htaccess, changing the path elsewhere appends the query in the end. How can I remove?
Redirect 301 /blog/category /blog/archive

Is the line I have in my .htaccess
So if I go to:
http://domain.com/blog/category/category-name
it takes me to:
http://domain.com/blog/archive/category-name?p=blog/category/category-name
What's going on here?

**Tags:** url, redirect, redirection

---

## 4 answers

### Answer by username_6 on 2014-07-11. Score: 21 | Accepted answer

The issue here is that your Redirect directive is conflicting with Craft’s index.php-hiding RewriteRule directive. (Redirect is a mod_alias directive and RewriteRule is a mod_rewrite directive. They’re two separate modules that can be used for the same thing, but lead to unexpected consequences when used together.)
To fix this, use a RewriteRule directive for your own custom redirects as well, rather than Redirect.
RewriteRule ^blog/category(/.*)?$ /blog/archive$1 [R=301,L]

Make sure that you place that before Craft’s redirect.

> **Comments:**
> **username_0**: That gives me a 404 :(  
> **username_0**: Is this meant to be in ADDITION instead of replacement? If it's in addition, I added the original Redirect above and then the one you have up there with the rewrite it still appends the URL  
> **username_6**: Should be a replacement. Old code out. This is what I used on an EE project where I was having this problem.  
> **username_2**: Make sure you place that _before_ Craft’s redirect.  
> **username_6**: Yes, mine is right after "RewriteEngine on". Adding that to my answer.  
> **username_0**: Noticed that this works if it's just /blog/category — it will redirect to /blog/archive. However, I need it to redirect when something is after it. e.g. /blog/category/category-name to /blog/archive/category-name  
> **username_2**: @lealea Ah, didn’t realize that’s what you wanted. Just updated the code.  

---

### Answer by username_1 on 2014-07-11. Score: 6

One way you can avoid this is by making a small change to the htaccess rules for removing index.php from Craft URLs. You can remove the query string from RewriteRule (.+) index.php?p=$1 [QSA,L] and replace it with /$1
So the full set of rules to remove index.php would be
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php/$1 [QSA,L]

This seems to work fine in my test and prevents the query string from being appended to the URL when using Redirect 301 in htaccess.

> **Comments:**
> **username_0**: In my tests, this seems to work! However, what are the possible side-effects of removing the ?p=  
> **username_2**: The only side effect of that change is it won’t work on servers that don’t support PATH_INFO. If it looks like it’s working for you, then great!  

---

### Answer by username_3 on 2014-07-11. Score: 2

What happens if you add a ? to the rule:
RewriteRule ^blog/category?$ /blog/archive [R=301,L,NE]

> **Comments:**
> **username_0**: Still gave me a 404  
> **username_2**: When you put a `?` right after another character in a regular expression, you’re just saying that whatever came before it is optional. So that pattern would match both “blog/category” and “blog/categor”. (Usually it’s good idea to put a `?` right before a trailing slash, so you’re matching both “blog/category/” and “blog/category”.)  
> **username_4**: s/right before a trailing slash/right after a trailing slash/  

---

### Answer by username_5 on 2016-03-29. Score: 0

If you need to remove these from search results, you may find this helpful: [Remove Query Strings from URLs](https://stackoverflow.com/questions/14071671/remove-query-string-from-end-of-url-url-using-htaccess)


---

