| Author | 
  | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Sun 26 May '13 13:54    Post subject: Troubles with .htaccess rewrite module - non www to www | 
     | 
 
  | 
 
Hi all!
 
 
I am facing some troubles with .htaccess file.
 
 
I am trying to force all non www traffic to www instead. My website is http://www.autojeesi.fi
 
 
I do not use index.shtml anymore as a first page, instead I want to use http:www.autojeesi.fi/auton-vuokraus.shtml as a primary first page of my site.
 
 
So this is why my.htaccess file looks like this for now. I think there might be something that is not compatible with the rewrite rules, but dont know what.
 
 
DirectoryIndex auton-vuokraus.shtml
 
Options All -Indexes
 
 
Redirect 301 /index.shtml /auton-vuokraus.shtml
 
Redirect 301 /yritys.shtml /autovuokraamo.shtml
 
AddHandler server-parsed .shtml
 
AddType text/html;charset=utf-8 .shtml
 
Options Includes
 
AddDefaultCharset utf-8
 
 
FileETag MTime Size
 
ExpiresActive on
 
ExpiresDefault "access plus 86400 seconds"
 
 
ExpiresByType image/gif "access plus 86400 seconds"
 
ExpiresByType text/css "access plus 86400 seconds"
 
ExpiresByType image/jpg "access plus 86400 seconds"
 
ExpiresByType image/png "access plus 86400 seconds"
 
 
ErrorDocument 404 /error404.shtml
 
 
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
 
BrowserMatch ^Mozilla/4 gzip-only-text/html
 
BrowserMatch ^Mozilla/4.0[678] no-gzip
 
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
 
 
<Files .htaccess>
 
order allow,deny
 
deny from all
 
</Files>
 
 
I have searched hours and hours the reason why I get error message:
 
 
Forbidden
 
 
You don't have permission to access / on this server.
 
 
When I add this to .htaccess:
 
RewriteEngine On
 
RewriteCond %{HTTP_HOST} ^autojeesi.fi
 
RewriteRule (.*) http://www.autojeesi.fi/$1 [R=301,L]
 
 
I have tried also tried to add [nc] with the same result:
 
 
RewriteEngine On
 
RewriteCond %{HTTP_HOST} ^autojeesi\.fi [nc]
 
RewriteRule (.*) http://www.autojeesi.fi/$1 [R=301,L]
 
 
Why is this happening? There are a lot of there rewriterule examples that have some minor differences in the internet and I have tried them but always the same result.
 
 
Do I have to do something on the server side?
 
 
I would really appreciate if anyone could help me out    | 
 
  | 
| Back to top | 
 | 
Steffen Moderator
 
  Joined: 15 Oct 2005 Posts: 3131 Location: Hilversum, NL, EU
  | 
 Posted: Sun 26 May '13 14:12    Post subject:  | 
     | 
 
  | 
 
Try: 	  | Code: | 	 		  RewriteEngine on 
 
RewriteCond %{HTTP_HOST}   !^www\.autojeesi\.fi [NC]
 
RewriteCond %{HTTP_HOST}   !=""
 
RewriteRule ^/(.*)         http://www\.autojeesi\.fi/$1 [L,R=301] | 	  
 
 
Steffen | 
 
  | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Sun 26 May '13 14:26    Post subject:  | 
     | 
 
  | 
 
Thanks your reply. It surely looks better now. Now if I write exact address they works well. But if I just write autojeesi.fi it still gives me the error message:
 
Forbidden
 
 
You don't have permission to access / on this server.
 
 
Same happens if I write just www.autojeesi.fi or http://autojeesi.fi
 
 
How is actually your way to do this differ from the one I tried? I would like to understand more this.
 
 
edit: By exact address I mean www.autojeesi.fi/auton-vuokraus.shtml for example | 
 
  | 
| Back to top | 
 | 
Steffen Moderator
 
  Joined: 15 Oct 2005 Posts: 3131 Location: Hilversum, NL, EU
  | 
 Posted: Sun 26 May '13 14:35    Post subject:  | 
     | 
 
  | 
 
| What is within your directive <Directory /> | 
 
  | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Sun 26 May '13 14:45    Post subject:  | 
     | 
 
  | 
 
I suppose you mean what I have in the directory where my website locates. (Im sorry I am quite unfamiliar with all the terms). 
 
 
The directory is located in /username/public_html/prod and there are now 
 
 
- bunch of shtml files
 
- .htaccess
 
- .htpasswd
 
- some .php files that are used as websites too
 
- images
 
- css file
 
- sitemap xml
 
- robots.txt | 
 
  | 
| Back to top | 
 | 
Steffen Moderator
 
  Joined: 15 Oct 2005 Posts: 3131 Location: Hilversum, NL, EU
  | 
 | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Sun 26 May '13 15:55    Post subject:  | 
     | 
 
  | 
 
| Thanks, i will request the credentials to access the server. | 
 
  | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Mon 27 May '13 19:03    Post subject:  | 
     | 
 
  | 
 
Hi!
 
 
I can't get access to httpd.conf file. However it should be ok.
 
 
I found out that the one that is makint the Forbidden 403 error to occur is this peace of code:
 
 
AddHandler server-parsed .shtml
 
 
Is there alternative way for that so everything would work? | 
 
  | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Mon 27 May '13 19:35    Post subject:  | 
     | 
 
  | 
 
Actually now I think I got it more specific. I have changed the index.shtml to auton-vuokraus.shtml and that actually must be allowed in that httpd.conf file.
 
 
Am I on the right track?    | 
 
  | 
| Back to top | 
 | 
Mikanas
 
 
  Joined: 26 May 2013 Posts: 7 Location: Finland, Helsinki
  | 
 Posted: Mon 27 May '13 20:45    Post subject:  | 
     | 
 
  | 
 
Ach! I found the mistake and didn't need to edit httpd.conf. 
 
 
This one broke it down:
 
AddType text/html;charset=utf-8 .shtml
 
 
I changed it to:
 
AddType text/html .shtml
 
 
Also I changed this:
 
Options Includes 
 
 
to this:
 
Options +IncludesNoExec -ExecCGI
 
 
Now it seems to work just fine.. | 
 
  | 
| Back to top | 
 | 
Steffen Moderator
 
  Joined: 15 Oct 2005 Posts: 3131 Location: Hilversum, NL, EU
  | 
 Posted: Mon 27 May '13 21:22    Post subject:  | 
     | 
 
  | 
 
Good to hear that you solved it. We all learn from it.
 
 
Steffen | 
 
  | 
| Back to top | 
 |