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
-
How to handle SEO redirection after remove www
Recently our https://bestclassifiedsusa.com free classifieds USA website we move from www to non www format. Now old urls still showing in Google SERP. When click they show 404 error pages due to removed old ads.
Technical SEO | | bcuclassifieds
We redirect www to non www version for main domain but still old cache pages affected.
How to dynamically handle this case, all old www version ads pages auto redirect to relevant category pages?0 -
Having issues with Redirects not working and old links on SERP
We just migrated a site and built a redirect map for Site A to B. If there were old redirects made for site A that weren't pulled when pulling internal links for site A, do those also need to be redirected to site B to eliminate a Redirect chain? Cannot figure out why old links are still showing up, does it take a few days for google to figure out these are not real pages?
Technical SEO | | Ideas-Collide0 -
How to explain "No Return Tags" Error from non-existing page?
In the Search Console of our Google Webmaster account we see 3 "no return tags" errors. The attached screenshot shows the detail of one of these errors. I know that annotations must be confirmed from the pages they are pointing to. If page A links to page B, page B must link back to page A, otherwise the annotations may not be interpreted correctly. However, the originating URL (/#!/public/tutorial/website/joomla) doesn't exist anymore. How could these errors still show up? Screenshot%202016-07-11%2017.36.27.png?dl=0
Technical SEO | | Maximuxxx0 -
Screaming Frog showing 503 status code. Why?
Screaming Frog is showing a 503 code for images. If I go and use a header checker like SEOBook it shows 200. Why would that be? Here is an example link- http://germanhausbarn.com/wp-content/uploads/2014/07/36-UPC-5145536-John-Deere-Stoneware-Logo-Mug-pair-25.00-Heavy-4-mugs-470x483.jpg
Technical SEO | | EcommerceSite0 -
Penalized domain redirected to the non-penalized one...
I've a technical question , For example site A was penalized by google updates, panda and penguin both and site b is in the same niche and it's running good and never been penalized by updates. If I redirect site A to Site B with 301 status code(permanent redirect), will Google penalize the site B too? because penalties travel from old domain to new one as per google's algorithms. And If yes then how can I stop my competitor from removing redirection of penalized domain to mine?
Technical SEO | | hammadrafique0 -
Secure and non-secure Schema.org Markup?
Is it possible to have schema.org itemtypes for both secure and insecure ports? I run a static-ish site made in Jekyll, and am implementing Schema.org on the individual pages. As a result, I'm trying to use the following: This doesn't validate with Google's Rich Snippet Tool. It doesn't register the Items as existing. Is there a good way to implement Schema.org in a static page hosted on both SSL and non-SSL ports?
Technical SEO | | RoxBrock0 -
Searching in Google using the Site:www.example.com specification - is it in an order?
Hi Gurus, Just a quick searching question. If you do a Google search using the site: specification eg. site:www.example.com Is the list returned by Google in an order of something similar to 'Page Authority' or some other order eg. page first seen date etc. Because you are looking at your single site, is Google listing your pages back to you in it's perceived order of current 'popularity'? Thanks, Brad
Technical SEO | | BM70 -
Www or no www in search results??
I am working with a client, and when I check on SERP placement, I never see the "www" in the SERP's only nameofcustomer.com not www.nameofcustomer.com. Of course there is a redirect going on...Question is...should this matter at all? I dont understand the relationship between this kind of redirect and SEO. Thank Mozzers
Technical SEO | | Giggy0