Where to put the .htaccess file

463 views
Skip to first unread message

Yannick

unread,
Aug 7, 2011, 2:18:15 PM8/7/11
to web2py-users, MDiP...@cs.depaul.edu
Hello mate,
I want to force "www" in front of the url and i modify the .htaccess
file to do so and now I wonder where to put that file. I tried to put
it in the "web2py/apps" directory, in the "web2py/apps/views"
directory, in the "web2py/" directory but none of them works.
I'm using apache as webserver.

Please let me know if you have any idea.

Thanks
Message has been deleted

Kenneth Lundström

unread,
Aug 7, 2011, 2:24:53 PM8/7/11
to web...@googlegroups.com

I think you have to put everything in either httpd.conf or then in the
virtual conf file you maybe have for every domain name. As wsgi is
proably used .htaccess is not read.

This is how I have understood it, maybe I�m totally wrong.


Kenneth

Yannick

unread,
Aug 7, 2011, 2:53:24 PM8/7/11
to web2py-users
Thanks for the reply.
Here is the code I use to force "www" in the .htaccess file:

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

Well I tried to put the same code in httpd.conf file but it doesn't
work, I have a "Syntax Error" when restarting apache because the
command "RewriteEngine " is not recognized.

Don't know how to force the "www" with web2py.


On Aug 7, 2:24 pm, Kenneth Lundström <kenneth.t.lundst...@gmail.com>
wrote:

Massimo Di Pierro

unread,
Aug 7, 2011, 6:28:05 PM8/7/11
to Yannick, web2py-users
Why? Do you want the web2py app to handle htaccess permissions?
Before you do that try look into this instead
scripts/access.wsgi

Massimo

On Aug 7, 2011, at 1:18 PM, Yannick wrote:

> Hello mate,

yannick Tchatchoua

unread,
Aug 7, 2011, 8:27:06 PM8/7/11
to Massimo Di Pierro, web2py-users
Actually I don't want Web2py to handle .htaccess file permission. What I want is to force the url to use "www" and I modify .htaccess file, my problem is I don't know where to put the file ? Can you point me out where I can put that file. 
If no can you tell me how I can resolve that issue ?

Thanks.
Cheers,
Yannick P.

Kenneth Lundström

unread,
Aug 8, 2011, 12:58:24 AM8/8/11
to web...@googlegroups.com
> Well I tried to put the same code in httpd.conf file but it doesn't
work, I have a "Syntax Error" when restarting apache because the command
"RewriteEngine " is not recognized.

Do you have this line in the httpd.conf file:

LoadModule rewrite_module modules/mod_rewrite.so

Without it, it won't work.


Kenneth

Mirek Zvolský

unread,
Aug 9, 2011, 12:40:02 PM8/9/11
to web2py-users
>> problem is I don't know where to put the file .htaccess ?

I am new and I don't know how to do things properly. But for testing I
have installed web2py on alwaysdata 10M free server as follows:

1. Under their /www folder I have /www/web2py with standard web2py
tree, include my application mywebapp
2. In addition I have folder /www/web2py/public
3. In alwaysdata administration, section Domains, I have the entry:
Name=mywebapp.alwaysdata.net, Path=/www/web2py/public
4. In /www/web2py/public I have .htaccess and web2py.cfgi
5. In addition I have folder /www/web2py/public/mywebapp/static with
all static files (instead off /www/web2py/applications/mywebapp/
static)

** Here is .htaccess:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web2py.fcgi/$1 [QSA,L]

** Here is web2py.cfgi:
#!/usr/bin/python
import os, sys
_PROJECT_DIR =
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, _PROJECT_DIR)
os.chdir(_PROJECT_DIR)
import gluon.main
import gluon.contrib.gateways.fcgi as fcgi
fcgi.WSGIServer(gluon.main.wsgibase, environ={'web2py_path':
_PROJECT_DIR}).run()

Yannick

unread,
Aug 11, 2011, 12:08:38 PM8/11/11
to web2py-users, Massimo Di Pierro
hi mate,
I put the .htaccess file in "/home/www-data/" directory in the same
directory as web2py dir. Now it seems to work. When i type the URL the
WWW is added in front of it like i wanted BUT the new issue is the
following:

when i type mywebsite.com it gets redirect to www.mywebsite.com/web2py/wsgihandler.py/

I wonder and don't understand why it goes to "/web2py/
wsgihandler.py/" ??

Please help it you know
Yannick P.

Yannick

unread,
Aug 11, 2011, 9:33:37 PM8/11/11
to web2py-users
I found the solution:

I put the ".htaccess" file in the "/home/www-data" directory and then
I remove the "/$1" in the URL link inside the command... here is the
command inside the ".htaccess" file.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mywebsite.com
RewriteRule (.*) http://www.mywebsite.com [R=301,L]

Cheers,
Yannick P.
Reply all
Reply to author
Forward
0 new messages