Jump to content

www to non-www .htaccess mod...


douglas81
 Share

Recommended Posts

There's an option in the current .htaccess to forward to the www version of your site. But...

I prefer a URLs without a www. However, I would still like said URLs to be accessible should someone type in the www sub-domain in their URL bar, or link to the "www version" of the URL. If you're like me, this could be a useful addition to the .htaccess file...

  # -----------------------------------------------------------------------------------------------
  # OPTIONAL: Redirect users to the non 'www.' version of the site (uncomment to enable).
  # For example: http://www.processwire.com/ would be redirected to http://processwire.com/
  # -----------------------------------------------------------------------------------------------
  
  #RewriteCond %{HTTP_HOST} ^www\.
  #RewriteCond %{HTTPS}s ^on(s)|off
  #RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
  #RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]

For me, this is the simplest way to do things. It also means any auto-populated canonical tags, such as...

<link rel="canonical" href="<?php echo $page->httpUrl; ?>">

...will never display the www version of your site.

I know many of you will know this already, but I always forget exactly what to put in there, so this will come in useful for me and others in future, I hope!

What are your thoughts on this? Some other solutions? I've heard about mod_alias also? How would that work in conjunction with ProcessWire? Would it be a better solution?

  • Like 2
Link to comment
Share on other sites

For canonical, why not type the hostname static and append the $page->url ? Or am I missing something ?

I just wonder if that rubs against the grain of ProcessWire a bit...? I like the idea in ProcessWire that everything is relative and that you can just drag an installation to another folder (or, indeed, domain name), if you so desire.

Link to comment
Share on other sites

Although, if you like to copy and paste re-usable template fragments from site to site, being able to use page->httpUrl has it's merits.

Actually, slightly OT, but that brings up another canonical question... how does one deal with https:// vs http:// in canonical? I mean, does that matter for SEO?

Link to comment
Share on other sites

You could force the scheme in your template settings.

For SEO, I really don't know. But I think if you don't communicate that you serve HTTPS next to HTTP, I don't think search engines will try to crawl the whole site again over HTTPS. And if it does I can't imagine you'll get bad points for it. Correct me when i'm wrong.

offtopic, $page->httpUrl very handy for newsletters :-)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...