Non-www to www code not working in htaccess
-
I use the same rewrite code on every site to consolidate the non-www and www versions.
All sites in Joomla, linux hosting. Code is as follows:
RewriteEngine On
rewritecond %{http_host} ^site.com/
rewriteRule ^(.*) http://www.site.com/$1 [R=301,L]
Immediately following this code, I also rewrite /index.php to /.
Thing is, I can get index.php to rewrite correctly but the non-www won't rewrite to www.
I use the same code on every site but for some reason it's not working here.
Are there common issues that interfere with rewriting a non-www to www in htaccess that could be interfering with the code I'm using above?
-
You're very welcome
BTW, I use SH404SEF with Joomla too, which is pretty good, but is a paid-for product.
-
Hi Jassy,
Thanks for your response. I was already using +followsymlinks.
Just tried your code and it did the trick!
Thanks a bunch
-
An alternative that I've had working on Joomla sites is:
#add www
RewriteCond %{HTTP_HOST} ^site.com$ [NC]
_ RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]_
RewriteCond %{THE_REQUEST} !^POST
#remove /index.php and ensure admin works okay
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{THE_REQUEST} ^.*/index.php\ HTTP/
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
One final thing, have you tried using
Options +FollowSymLinks
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Why are Google SERP Sitelinks "Not Working?"
Hi, I'm hoping someone can provide some insight. I Google searched "citizenpath" recently and found that all of our our sitelinks have identical text. The text seems to come from the site footer. It isn't using the meta descriptions (we definitely have) or even a Google-dictated snippet from the page. I understand we don't have "control" of this. It's also worth mentioning that if you search a specific page like "contact us citizenpath" you'll get a more appropriate excerpt. Can you help us understand what is happening? This isn't helpful for Google users or CitizenPath. Did the Google algorithm go awry or is there a technical error on our site? We use up-to-date versions of Wordpress and Yoast SEO. Thanks! search.png
Technical SEO | | 123Russ0 -
Www to non-www redirect without loop still necessary?
Hi Guys, My question is: Is it still necessary to redirect www. to non www. version of your website or other way around?
Technical SEO | | gaben
I ask because I feel that Google should be able to read these as the same by now. Thank you in advance.
Gabe0 -
Schema.org markup for breadcrumbs: does it finally work?
Hi, TL;DR: Does https://schema.org/BreadcrumbList work? It's been some time since I last implemented schema.org markup for breadcrumbs. Back then the situation was that google explicitly discouraged the use of the schema.org markup for breadcrumbs. In my experience it had been pretty hit or miss - sometimes it worked without issues; sometimes it did not work without obvious reason. Consequently, I ditched it for the data-vocabulary.org markup which did not give me any issues. However, I prefer using schema.org and currently a new site is being designed for a client. Thus, I'd like to use schema.org markup for the breadcrumb - but of course only if it works now. Google has dropped the previous warning/discouragements and by now lists a schema.org code https://developers.google.com/structured-data/breadcrumbs based on the new-ish https://schema.org/BreadcrumbList. Has anybody here used this markup on a site (preferably more than one) and can confirm whether or not it is reliably working and showing the breadcrumb trail / site hierarchy in the SERP? Thanks for your answers! Nico
Technical SEO | | netzkern_AG0 -
.htaccess Redirect 301 issues
I have completely rewritten my web site, adding structure to the file directories. Subsequently added was Redirect information within the .htaccess file. The following example ...
Technical SEO | | Cyberace
Redirect 301 /armaflex.html http://www.just-insulation.com/002-brands/armaflex.html
Returns this response in the URL bar of ...
http://www.just-insulation.com/002-brands/armaflex.html?file=armaflex
I am at a loss to understand why the suffix "?file=armaflex" is added The following code is inserted at the top of the file ...
RewriteEngine On redirect html pages to the root domain RewriteRule ^index.html$ / [NC,R,L] Force www. prefix in URLs and redirect non-www to www RewriteCond %{http_host} ^just-insulation.com [NC]
RewriteRule ^(.*)$ http://www.just-insulation.com/ [R=301,NC] Any advice would be most welcome.0 -
Using a non-visible H1
I have a developer that wants to use style="text-indent:-9999px" to make the H1 non-visible to the user. Being the conservative person I am, I've never tried this before and worry that Search Engines may think this is a form of cloaking. Am I worrying about nothing? And apologies if it's already been covered here. I couldn't find it. Thanks in advance!!!!
Technical SEO | | elytical0 -
My .htaccess has changed, what do i do to avoid it again...?
Hello Today i notice that our site did not auto changed from without www to with, when i checked the .htaccess file i notice # in-front of each line and i know we did not insert it in there, after i removed it it worked fine. The only changes that we did recently was to a mobile version to the site but the call to autodirect is in a JS and not in the .htaccess, could it be the server..? is there any way that anything else might cause this...? The site is HTML and WP could it be because of that...? Thank's Simo
Technical SEO | | Yonnir0 -
Seeing non-www in yahoo results - good or bad?
My site ranks for both domain versions but more non-www than www - Should I make it one or the other? How do I tell Yahoo to just choose one? Ehh?
Technical SEO | | DavidS-2820610 -
How do doorway page penalties work?
In case of a doorway page penalty, are both the doorway page and the external domain affected?
Technical SEO | | nicole.healthline0