Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

How do I force canonical URL in Grav?

first-time

Solved by Ivan Montilla Miralles View solution

Started by Ivan Montilla Miralles 5 years ago · 1 replies · 986 views
5 years ago

Good evening my friends,

I'm happy to use Grav for my personal blog and site. I've always been an anti-mainstream guy.

Anyway, I found out my site is both accessible at https://mydomain.com/ and https://www.mydomain.com. I wish the latter to remain, and whenever it's accessed without the "www." redirect permanently to the "www." version.

How'd I achieve this? I tried modifying it with custom_base_url, but I think I'm doing it wrong.

Thanks in advance,

5 years ago Solution

Solved it myself with .htaccess wizardry.

I added the following:
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ "https\:\/\/www\.mydomain\.com\/$1" [R=301,L]

Before the rules of:
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 491 6 days ago
Support · by Lauw, 1 week ago
2 107 1 week ago
Support · by Anna, 3 weeks ago
4 431 1 week ago
Support · by gtx, 4 weeks ago
4 380 3 weeks ago
Support · by Anna, 1 month ago
9 487 4 weeks ago