Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

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.

share|improve this answer
    
That gives me a 404 :( –  lealea Jul 11 at 16:15
    
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 Jul 11 at 16:17
    
Should be a replacement. Old code out. This is what I used on an EE project where I was having this problem. –  Anna_MediaGirl Jul 11 at 16:41
1  
Make sure you place that before Craft’s redirect. –  Brandon Kelly Jul 11 at 16:46
    
Yes, mine is right after "RewriteEngine on". Adding that to my answer. –  Anna_MediaGirl Jul 11 at 17:16

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.

share|improve this answer
1  
In my tests, this seems to work! However, what are the possible side-effects of removing the ?p= –  lealea Jul 11 at 16:34
1  
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 Jul 11 at 16:40

What happens if you add a ? to the rule:

RewriteRule ^blog/category?$ /blog/archive [R=301,L,NE]
share|improve this answer
    
Still gave me a 404 –  lealea Jul 11 at 16:44
    
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 Jul 11 at 17:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.