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
-
Htaccess redirects
Annoyingly it's time to play with this beast again. I've been given the task of doing the following. Keeping the homepage live Redirecting categories to the specific categories on the new site Catch all redirects Now i've managed to setup the specific categories and the catch all redirects, however I am unsure how to keep the homepage live (which is like this:www.domain.com/ so I can't just exclude that?) Would appreciate any help.
Technical SEO | | ThomasHarvey0 -
Cannot work out why a bunch of urls are giving a 404 error
I have used the Crawl Diagnostic reports to greatly reduce the number of 404 errors but there is a bunch of 16 urls that were all published on the same date and have the same referrer url but I cannot see the woood for trees as to what is causing the error. **The 404 error links have the structure:**http://www.domainname.com/category/thiscategory/page/thiscategory/this-is-a-post The referrer structure is: http://www.domainname.com/category/thiscategory/page/2/ Any suggestions as to how to unravel this would be appreciated.
Technical SEO | | Niamh20 -
.htaccess and error 404
Hi, I permit to contact the community again because you have good and quick answer ! Yesterday, I lost the file .htaccess on my server. Right now, only the home page is working and the other pages give me this message : Not Found The requested URL /freshadmin/user/login/ was not found on this server Could you help me please? Thanks
Technical SEO | | Probikeshop0 -
Htaccess help... I moved my blog from a seperate domain to newdomain.com/blog
Hi, I need help with my htaccess file, I've been told. I moved a blog i had hosted somewhere else to a directory on my ecommerce site. I was told i would need to write something to go in the htaccess file so the sites would not become duplicate content, but I'm a novice and have no idea how to write that code. blog moved from www.whosyourmoondoggie.com to www.moondoggieinc.com/blog Please help, or direct me to the right tutorial 🙂 Thanks! KristyO
Technical SEO | | KristyO0 -
Smart phone shows both mobile & desktop version of www.innoviafilms.com
Good morning from 2 degrees C mostly cloudy wetherby UK, Image this situation... Ive got two versions of a website: A desktop version & a mobile version, here are their respective urls: Desk top: http://www.innoviafilms.com Mobile: http://www.innoviafilms.com/m/home.aspx With blackberry bold in hand I type in via google search "Innovia films" i click on the search snippet and it renders the desktop version. But when i type the url directly in my Blackberry bold 9700 it returns the mobile version 😞 This confuses me. Having read this: http://googlewebmastercentral.blogspot.com/2011/02/making-websites-mobile- friendly.html I thought the desktop version would render in smartphones which the balckberry bold is. So my question is... "Why does the the mobile version only appear when you type in www.innoviafilms.com on a blackberry (and iphone 4) and the desktop version appears only when you enter "Innovia films" via google search" Any insights welcome 🙂
Technical SEO | | Nightwing0 -
Putting nav code at the bottom of a page?
Hey, We are doing a re-design on our websites and we have run into a little problem. Basically we need to put the nav code at the bottom of the page (so when you view source all the nav code it at the bottom) but the nav will of course still show at the top. Will this cause any issues with our SEO? Will it make the nav seem less important or get crawled less? Thanks for the help in advance! Ricky
Technical SEO | | Fubra0 -
IIS Work Around 301 Redirects
We are redirecting page-level content (about 500 pages) from several sub domains to our main site. With IIS, It’s my understanding that file locations must match. For example: subdomain/pathA/filename1
Technical SEO | | DigitalMkt
mainsite/pathA/filename1 Since the sub domain files are not on the main site, this means we'd create up to 500 zero byte dummy files on the new server and replicate the sub domain directory structure. With IIS is there a work around for handling page level redirects without duplicating the file location? In the case of white papers, videos and case studies, we'll imlement directory level redirection. Thanks in advance.0 -
My website pages (www.ommrudraksha.com) is getting good rank slowly. But no good sales ?
My website has been doing good slowly. I have been using seomoz recommendations. And it is a great help to see that my pages are slowly coming to the first page. I am also running PPC on google. I see there are many visitors to my website. But i do not get good conversion - or not getting customer buying products. My website : www.ommrudraksha.com My target keyword is : rudraksha
Technical SEO | | Ommrudraksha0