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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Problem with "www" and non "www"

Started by Muut Archive 12 years ago · 8 replies · 1013 views
12 years ago

My site dns is setup correctly to point all non "www" to www. For example all urls should be www.mikecapson.com. However I am having issues as the Grav install seems to be forcing it without the www. Also I can reach internal images the way it is now however if I add in the www to the url I get a 404 for images. I'm not sure the area to check to resolve this issue. I have checked the htacces and didn't notice anything unusual.

My install is installed in a vhost under var/vhost/mikecapson.com/installedhere

Any help would be appreciated.

12 years ago

Do you have a public URL i can look at? And how exactly is your www. url being redirected to non-www. ? Is this an .htaccess thing? or purely a DNS thing?

12 years ago

mikecapson.com is the public url. My dns is handling the redirect.

12 years ago

Ok, so just for clarity. http://mikecapson.com does not redirect, to http://www.mikecapson.com, it just seems to be an alias to www. Grav get's the hostname for URLs directly from PHP's $_SERVER['SERVER_NAME'] variable, and that is usually the same as the URL in the browser.

The best way to ensure that PHP has the correct name is to actually do a redirect rather than alias. Here you can see how to use .htaccess to redirect non-www to www URLs: http://dense13.com/blog/2008/02/27/redirecting-non-www-to-www-with-htaccess/

Grav linking to the full URL is a little strange, and i"m trying to work out why that is doing that. Let's use your navigation as an example. How exactly are you outputting your navigation menu? This theme is customized so I need to know how the page URLs are being generated. Then we can proceed with tracking it down why those are full and not relative...

12 years ago

To be specific I really need to see the content of your twig template that is outputting the menu.

12 years ago

BTW, we think we may of found an issue either directly causing your issue, or closely related, so we're investigating it.

12 years ago

OK we've fixed a couple of config caching bugs and pushed them to GitHub. However, i'm not convinced this is the cause of your issue. Could you first upgrade your Grav to 0.9.5 as your still on 0.9.4?

Easiest way is to do it via GPM from the command line (if possible):

BASH
bin/gpm selfupgrade
bin/gpm update

This will update Grav to latest version first, then the plugins and themes.

12 years ago

Iv updated to 0.9.5, i have implemented the redirect in my .htaccess to force the www.

In my theme the nav is hardcoded like below and works properly once the .htaccess was implemented:

---html
<nav class="main-navigation-container">
<ul class="main-navigation">
<li><a href="{{ base_url_absolute }}/portfolio/portraiture-photography">Portraits / Editorial</a></li>
<li><a href="{{ base_url_absolute }}/portfolio/advertising-photography">Advertising / Commercial</a></li>
<li><a href="{{ base_url_absolute }}/portfolio/architecture-photography">Architecture / Interiors</a></li>
<li class="menu-spacer"></li>
<li><a href="{{ base_url_absolute }}/about">About</a></li>
<li><a href="{{ base_url_absolute }}/projects">Projects</a></li>
<li><a href="{{ base_url_absolute }}/journal">Journal</a></li>
<li><a href="http://society6.com/mikecapson/framed-prints">Shop</a></li>
<li><a href="{{ base_url_absolute }}/contact">Contact</a></li>
</ul>
</nav>

TXT


Also this seems to have fixed the issues with linking as I had asked above.

Thanks for the support!
12 years ago

Ok awesome! One thing you might want to do is replace base_url_absolute with base_url_relative to save a little space and make things cleaner.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1279 9 years ago
Archive · by Muut Archive, 9 years ago
2 886 9 years ago
Archive · by Muut Archive, 9 years ago
2 4015 9 years ago
Archive · by Muut Archive, 9 years ago
1 2891 9 years ago
Archive · by Muut Archive, 9 years ago
3 1075 9 years ago