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
-
Rel Canonicals not working properly.
We recently implemented rel=canonicals on a few of our pages to prevent query parameters from showing up in the SERPs. The two pages we added the tags to are no longer ranking. The pages used to rank very well for branded terms such as "morningstar direct" and "morningstar sustainability", but now don't show up at all. When you search for the urls specifically, for example "products/direct morningstar" the query parameter is still indexing. Does anyone know why this might be or what we can do to fix this issue? The two pages are www.morningstar.com/products/direct and https://www.morningstar.com/company/sustainability
Technical SEO | | jmigdal0 -
Bing Webmaster Shows Domain without WWW
One of our sites shows thousands of 301 redirects due to domain without www in Bing Webmaster under crawl Information page. It’s been like this for a long time. None of the internal pages have domain without www, it was tested through Screaming Frog. We do have www preference set in google webmaster, but unfortunately bing doesn’t have this option. We also specify URL with www preference through structural data, but that still doesn’t help. Did anyone have similar problems with Bing, and how did you resolve it?
Technical SEO | | rkdc1 -
.htaccess code
I've got a .htaccess file set up on a site to redirect specific old pages to specific new pages on a different site: eg Redirect 301 /oldpage.html https://www.newsite.co.uk/newpage.html Redirect 301 /oldpage2.html https://www.newsite.co.uk/folder/ I have two questions: 1. Is that all the file needs? Or does it need any "rewrite engine on" type code? 2. I would also like to include code to "mop up" any other URLs and redirect them to the root, so that /anyotherpage.html redirects to newsite.co.uk Is there a way to do this?
Technical SEO | | abisti20 -
From: http://www. to https://
Hi all, I am changing my hosting for legal and SEO reasons from http://www to https:// . Now I hear different stories on the redirects: 1: should i try and change my backlinks? 2: internally all links will be 301 redirected at first. Than I want to (manually) change them. It;s within Wordpress so there should be a plugin for this. Tips? 3: Will it affect my rankings and for what period? What I now know that at first it will drop little but eventually you will rank higher than before. Thanks so much in advance! Tymen
Technical SEO | | Tymen1 -
Help creating a 301 redirect in my htaccess file
Hi Guys, I'm trying to build a 301 file with the file requirements: It should be visible only for Google and other Search Engine Agents. It will have a few direct redirects. A few URL must be dynamic redirect. For example each page the starts with olddomain.com/category and is not in the list of of direct redirects should be redirect for newdomain.com/category Here is my start point: #301 Starts here Set the agents RewriteEngine On
Technical SEO | | Felip3
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} Slurp Make the direct redirect. Redirect 301 /category/sub1 http://www.newdomain.com/category/sub1
Redirect 301 /category/sub2 http://www.newdomain.com/category/sub2 Redirect everything else Redirect 301 /category/* http://www.newdomain.com/category #End of my 301 Will that work how I want? is there anything wrong?0 -
How to know that i work well in my rank ?
Hi everyone, i'd like to know if i rank my keywords , how to know that i do well? every day
Technical SEO | | engmtamous0 -
Pointing a sub-domain to a sub-folder in htaccess
I have a client who currently uses shopify for there blog. I want to set them up with a separate blog away from the shopify system and host it in Australia. I know the best option is using a subfolder but as the shopify system is an unmoveable CMS can I somehow point my subdomain to a subfolder and get the benefits of the domain name? I could do this by using the rewrite rule in the htaccess file. If I was to do this would it end up cloaking the URL's of the articles?
Technical SEO | | acs1110 -
Website Structure - What works best for passing the Link Juice?
As most people know it's usual that the main menu is after the top right small links in html. My questions are: What is more important for google or how does google tell which link is more important than the other to pass juice on? If the top right links are in front of the main menu in html would they get more link juice than the main menu? Should i focus in working on better html structure but still keeping the same look ( reverse the html code but keep the same look through css)? Any suggestions?
Technical SEO | | mosaicpro0