Advertisement:

Author Topic: www and non www domain  (Read 405 times)

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
www and non www domain
« on: December 26, 2017, 03:30:50 PM »
Hi Guys n Girls, looking for help on a problem I'm having with www and non www versions of my site.

Quote
Details:
Domain - www.fordmpv.com [nofollow]
Host - 1and1.co.uk
SMF Location - root\smf2
index.html in root contains redirect to root\smf2 as no 'site' just the forum

So my problem is that the site is accessible by both www.fordmpv.com [nofollow] and fordmpv.com however I cant find a way to fix this. I read extensively about using rewrite in .htaccess so I added:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^fordmpv.com
RewriteRule (.*) http://www.fordmpv.com/ [nofollow]$1 [R=301,L]

However with that in, only the SMF boardindex page works. Any link clicked gets a 404 page. I've confirmed the boardurl is settings.php is the www version so I'm at a loss how to make this work. Any pointers?

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,333
  • There's someone in my head but it's not me.
Re: www and non www domain
« Reply #1 on: December 26, 2017, 04:02:45 PM »
Do you want fordmpv.com and www.fordmpv.com to redirect to www.fordmpv.com/smf2?

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
Re: www and non www domain
« Reply #2 on: December 26, 2017, 04:14:16 PM »
Yes. there is no site hosted there its purely the forum and a few subdomains using the rest of the webspace.
Cheers :)

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,333
  • There's someone in my head but it's not me.
Re: www and non www domain
« Reply #3 on: December 26, 2017, 04:25:14 PM »
Try this -

Code: [Select]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^fordmpv\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.fordmpv\.com$
RewriteRule ^/?$ "http\:\/\/www\.fordmpv\.com\/smf2\/index\.php\?"
[R=301,L]


Place it in the root, remove index.html.

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
Re: www and non www domain
« Reply #4 on: December 26, 2017, 05:52:33 PM »
Humm no it didn't like that lol. Resulted in 500 Internal Server Error for all pages :(

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,333
  • There's someone in my head but it's not me.
Re: www and non www domain
« Reply #5 on: December 26, 2017, 09:55:53 PM »
Should work, it's running on another forum with same setup as yours.  Not on my computer, will check the code tomorrow.  Are you using http or https?

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
Re: www and non www domain
« Reply #6 on: December 27, 2017, 05:09:15 AM »
Thanks :)

Http, getting this working is part of the work I'm doing in preparation to switch to https

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
Re: www and non www domain
« Reply #7 on: December 27, 2017, 05:42:19 AM »
Although not part of the problem (for the moment) just to add that trying the forum in https mode using the redirect code:

Code: [Select]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I get the same issue as per my first post with this code:

Code: [Select]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fordmpv.com
RewriteRule (.*) http://www.fordmpv.com/ [nofollow]$1 [R=301,L]

except the pages are just blank non 404, interestingly that's what I now get with the original code  :'(

Online Aleksi "Lex" Kilpinen

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,911
  • Gender: Male
  • The Artist Formerly Known as LexArma
    • Aleksi.Kilpinen on Facebook
    • aleksi-kilpinen on LinkedIn
Re: www and non www domain
« Reply #8 on: December 27, 2017, 05:44:28 AM »
Humm no it didn't like that lol. Resulted in 500 Internal Server Error for all pages :(
This should leave a line in your server error log, perhaps see if there's a more detailed explanation. It may be something server specific, and as such a good idea to check the log.
Finnish Native Language Support Specialist & Former (Lead) Support Specialist

Offline Mirez

  • Semi-Newbie
  • *
  • Posts: 12
Re: www and non www domain
« Reply #9 on: December 27, 2017, 09:10:25 AM »
Thanks, so after some extensive googling with the error log and some more testing I traced the issue back to the prettyurls mod, specifically it creates its own .htaccess file in the forum directory, not the root, and browsers appear to disregard the root file once they see this one.

I disabled prettyurls, deleted its .htaccess file and then converted the site to https. Re-enabled the mod changing the "Pretty URL's Root" variable from www.fordmpv.com/smf2/ [nofollow] to just /smf2
This appears to have fixed it and I now have access for all links and boards on just "https:\\www." so thats good.

Thanks to both above for the help!

I will need to do a little further work as occasionally some files are still being served as http but on the whole its working correctly.