0

I'm trying some 301 redirects in .htaccess.

I'm trying to redirect something like this:

http://creek.com/wines/red/greatwine

into

http://creek.com/shop/product/wines/red/greatwine

but I'm getting the following output

http://creek.com/shop/product/red/greatwine?/wines/red/greatwine

There are many different subdirectories under wines, so I need those to be wildcarded. I hope that makes sense.

Please see my .htaccess below. Thanks for any help!

RewriteEngine On
RewriteCond %{HTTP_HOST} !^creek.com$ [NC]
RewriteRule ^(.*)$ http://creek.com/$1 [L,R=301]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>

RedirectMatch 301 ^/wines/(.*)/(.*)$ http://creek.com/shop/product/$1
1
  • 2
    Your url goes first through the rewrite than through redirect (and you can't change the order). Convert the redirect into a rewrite and place it before the other redirect rules. – Dan May 16 '15 at 13:15
0

@Dan is right.

You should convert your RedirectMatch into a Rewrite and place it before your <IfModule mod_rewrite.c> block :

RewriteCond %{REQUEST_URI} ^/wines/(.*)/(.*)
RewriteRule ^(.*)$ http://creek.com/shop/product/$1 [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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