1

Hi I'm having major problems trying to get my .htaccess file to rewriteRule or redirect one url to another. I've used .htaccess before on other cms installs and always work but for the life of me I cannot get it to work on my craft install.

<IfModule mod_rewrite.c>


    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    # 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?p=$1 [QSA,L]

    Redirect /outdoor-furniture/all-garden-benches https://www.mywebsite.co.uk/outdoor-furniture/garden-benches


</IfModule>

This should redirect /outdoor-furniture/all-garden-benches to /outdoor-furniture/garden-benches (getting rid of the 'all-' bit).

This actually redirects to this:

https://www.mywebsite.co.uk/outdoor-furniture/garden-benches?p=outdoor-furniture/all-garden-benches

which is obviously wrong and still throws up a 404 error. I've tried everything now and what was supposed to be a 5 minute job is sending me round the bend so if anyone could shed some light on this then that would be great thanks!

EDIT The only thing that will help is if I take off ?p=$1 from this line:

 RewriteRule (.+) index.php?p=$1 [QSA,L]

Once I do that the redirect works fine, however I'm reluctant to do that as it might break the site somewhere.

1

You can try this

<IfModule mod_rewrite.c>


    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    # 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 ^/outdoor-furniture/all-garden-benches /outdoor-furniture/garden-benches [NC,L,R=301]

    RewriteRule (.+) index.php?p=$1 [QSA,L]


</IfModule>

If that doesn't work you can always try using a plugin for your redirects

  • Thanks, unfortunately that just gives me Page Not Found and also strips away all css. I'll check out the plugins... – cannon303 Sep 24 at 14:39
  • The redirect plugin worked! Thank you. I don't suppose I'll ever get to the bottom of the problem with the .htaccess file as clearly something is wrong but the plugin does the trick! – cannon303 Sep 24 at 14:49

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.