<p>Per Brad's request. I am answering my own question.</p>

<p>I figured out that I was logging in via non-www, and accessing the site at www.</p>

<p>So the official answer is to choose either www or non-www. I chose to remove the www from the URL.</p>

<p>Here's my .htaccess for that, including allowing for fonts to be accessed cross domain, as I had issues with this as well.</p>

<pre><code>&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On

    # Remove www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [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]
&lt;/IfModule&gt;

&lt;FilesMatch "\.(eot|ttf|otf|woff|svg)"&gt;
    Header set Access-Control-Allow-Origin "*"
&lt;/FilesMatch&gt;
</code></pre>

<p><strong>Note!!!</strong> Once this is done, make sure to clear your Craft cache., especially if using fonts/font-icons.</p>

CC BY-SA 3.0
2016-08-24T20:26:51.340Z
2016-08-24T20:26:51.340Z
Erik
<p>Does anyone know why <code>currentUser</code> would return null? I'm logged in as an admin.. actually the only user.</p>

<p>I've cleared cache, logged out and back in, etc. I can't seem to get it to work.</p>

<p>I'm trying to set an edit link for an entry like so:</p>

<pre><code>{% if currentUser %}
    &lt;a href="{{ entry.cpEditUrl }}"&gt;
        Edit
    &lt;/a&gt;
{% endif %}
</code></pre>

<p>And also tried this:</p>

<pre><code>{% if entry.isEditable() %}
    &lt;a href="{{ entry.cpEditUrl }}"&gt;
        Edit
    &lt;/a&gt;
{% endif %}
</code></pre>

<p>Neither are working. Any ideas?</p>

CC BY-SA 3.0
2016-08-24T18:16:11.563Z
Is this in the context or a normal template request? i.e. you're not doing something edge case like trying to add this code inside of a redirect Twig tag or something similar?
Brad Bell
CC BY-SA 3.0
2016-08-24T18:38:23.733Z
Normal template request. It was working fine the other day. I have looked through all my git commits, turned off plugins, etc and I cannot get it working again.
Erik
CC BY-SA 3.0
2016-08-24T18:49:19.727Z
Hate to ask the obvious, but you're positive you're logged in?
Brad Bell
CC BY-SA 3.0
2016-08-24T18:56:28.227Z
Yes, absolutely positive.
Erik
CC BY-SA 3.0
2016-08-24T18:57:32.327Z
Did you happen to update Craft between the time it was working and now?  If so, do you remember the version you were on?
Brad Bell
CC BY-SA 3.0
2016-08-24T18:58:36.143Z
I may have figured it out. I was logged in with non-www. But going to the front end with www. Is there a way to make Craft not care about www?
Erik
CC BY-SA 3.0
2016-08-24T20:06:21.160Z
You'd be better off picking either www or non-www as the canonical domain and forcing a rewrite from the other to that one: https://stackoverflow.com/questions/4916222/htaccess-how-to-force-www-in-a-generic-way - better for SEO as well because Google will index both as 2 separate sites instead of 1.
Brad Bell
CC BY-SA 3.0
2016-08-24T20:06:45.303Z
Be sure and add an official answer as well. ;)
Brad Bell
<templating><usermodel>
currentUser global is null. I can't figure out why
# currentUser global is null. I can't figure out why

(Asked by: username_0 on 2016-08-24)

Does anyone know why currentUser would return null? I'm logged in as an admin.. actually the only user.
I've cleared cache, logged out and back in, etc. I can't seem to get it to work.
I'm trying to set an edit link for an entry like so:
{% if currentUser %}
    
        Edit
    
{% endif %}

And also tried this:
{% if entry.isEditable() %}
    
        Edit
    
{% endif %}

Neither are working. Any ideas?

**Tags:** templating, usermodel
> **Comments:**
> **username_1**: Is this in the context or a normal template request? i.e. you're not doing something edge case like trying to add this code inside of a redirect Twig tag or something similar?  
> **username_0**: Normal template request. It was working fine the other day. I have looked through all my git commits, turned off plugins, etc and I cannot get it working again.  
> **username_1**: Hate to ask the obvious, but you're positive you're logged in?  
> **username_0**: Yes, absolutely positive.  
> **username_1**: Did you happen to update Craft between the time it was working and now?  If so, do you remember the version you were on?  
> **username_0**: I may have figured it out. I was logged in with non-www. But going to the front end with www. Is there a way to make Craft not care about www?  
> **username_1**: You'd be better off picking either www or non-www as the canonical domain and forcing a rewrite from the other to that one: https://stackoverflow.com/questions/4916222/htaccess-how-to-force-www-in-a-generic-way - better for SEO as well because Google will index both as 2 separate sites instead of 1.  
> **username_1**: Be sure and add an official answer as well. ;)  

---

## 1 answers

### Answer by username_0 on 2016-08-24. Score: 2

Per Brad's request. I am answering my own question.
I figured out that I was logging in via non-www, and accessing the site at www.
So the official answer is to choose either www or non-www. I chose to remove the www from the URL.
Here's my .htaccess for that, including allowing for fonts to be accessed cross domain, as I had issues with this as well.

    RewriteEngine On

    # Remove www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [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]



    Header set Access-Control-Allow-Origin "*"


Note!!! Once this is done, make sure to clear your Craft cache., especially if using fonts/font-icons.


---

