logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Troubles with .htaccess rewrite module - non www to www
Author
Mikanas



Joined: 26 May 2013
Posts: 7
Location: Finland, Helsinki

PostPosted: Sun 26 May '13 13:54    Post subject: Troubles with .htaccess rewrite module - non www to www Reply with quote

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 Smile
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3117
Location: Hilversum, NL, EU

PostPosted: Sun 26 May '13 14:12    Post subject: Reply with quote

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

PostPosted: Sun 26 May '13 14:26    Post subject: Reply with quote

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: 3117
Location: Hilversum, NL, EU

PostPosted: Sun 26 May '13 14:35    Post subject: Reply with quote

What is within your directive <Directory />
Back to top
Mikanas



Joined: 26 May 2013
Posts: 7
Location: Finland, Helsinki

PostPosted: Sun 26 May '13 14:45    Post subject: Reply with quote

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: 3117
Location: Hilversum, NL, EU

PostPosted: Sun 26 May '13 14:49    Post subject: Reply with quote

Nope I mean in httpd.conf the directive <Directory />, see http://httpd.apache.org/docs/2.4/mod/core.html#directory
Back to top
Mikanas



Joined: 26 May 2013
Posts: 7
Location: Finland, Helsinki

PostPosted: Sun 26 May '13 15:55    Post subject: Reply with quote

Thanks, i will request the credentials to access the server.
Back to top
Mikanas



Joined: 26 May 2013
Posts: 7
Location: Finland, Helsinki

PostPosted: Mon 27 May '13 19:03    Post subject: Reply with quote

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

PostPosted: Mon 27 May '13 19:35    Post subject: Reply with quote

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? Smile
Back to top
Mikanas



Joined: 26 May 2013
Posts: 7
Location: Finland, Helsinki

PostPosted: Mon 27 May '13 20:45    Post subject: Reply with quote

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: 3117
Location: Hilversum, NL, EU

PostPosted: Mon 27 May '13 21:22    Post subject: Reply with quote

Good to hear that you solved it. We all learn from it.

Steffen
Back to top


Reply to topic   Topic: Troubles with .htaccess rewrite module - non www to www View previous topic :: View next topic
Post new topic   Forum Index -> Apache