0

I am trying to get pretty urls

In my general.php file I have

'omitScriptNameInUrls' => true,

which works fine and removes the index.php

BUT

When I try to force a www in the htaccess the index.php comes back and I can't seem to remove this.

This is what I have in my htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Any thoughts?

2
  • Are you certain that you're using Craft 3? Otherwise we should remove the craft3 tag. (I'm not sure it's relevant anyway.) – Lindsey D Oct 29 '17 at 19:19
  • yeah I am using the latest craft – rcho Oct 30 '17 at 18:03
3

Your .htaccess is basically saying "Redirect example.com to www.example.com".

OK, that's cool. so you want to add www to any request that a comes in. I'm guessing you put this after Craft's code?

This actually needs to come before you send the request to Craft.

So, your example should look like this:

<IfModule mod_rewrite.c>

  #Make sure the rewrite engine is on
  RewriteEngine On

  # Redirect non-www requests to www
  RewriteCond %{HTTP_HOST} ^example\.com [NC] 
  RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

  # 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]

</IfModule>

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.