1

I'm building something with Craft and Vue.js and realized that I could view my page with or without a trailing slash, but when it had a trailing slash, my ajax calls to the Element API endpoint failed, thus the content wouldn't load. So I've changed all my endpoints to not include the .json like in the plugin's docs examples and just end in a /.

I'm not sure if it's better or worse to force a trailing slash (I've read arguments for either way online), but I figure it's best to just choose one and go with it, so I've chosen to force it, but then I can't log into my admin control panel anymore, and I get some javascript errors elsewhere on front-end pages.

Here's my .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On

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

    # 301 redirect with trailing slash
    RewriteCond %{REQUEST_URI} /+[^\.]+$
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

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

I'm also adding 'addTrailingSlashesToUrls' => true, in my config file.

How can I fix this to have trailing slashes, ensure that ajax calls don't fail, and still log into the cms? Or should I just force no trailing slash?

Your Answer

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

Browse other questions tagged or ask your own question.