mod_rewrite in .htaccess does not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaanus
    New Member
    • Sep 2007
    • 3

    #1

    mod_rewrite in .htaccess does not work

    Here we go...

    What I have been trying to do is to forward all http requests containing /cms/ to http://cms.mydomain.com/

    example1: http://host1.mydomain.com/cms/init.php would be parsed from http://cms.mydomain.com/init.php (via ajax request)

    example2: <script src="http://host1.mydomain. com/cms/example.js" in <html><head> would be parsed from http://cms.mydomain.com/example.js

    physically there are no cms directories in http://cms.mydomain.com/ nor in http://host1.mydomain.com/ nor in http://host2.mydomain.com/


    /var/www/host1.mydomain. com/web/.htaccess

    and

    /var/www/host2.mydomain. com/web/.htaccess

    look like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/cms/(.*)$ http://cms.mydomain.co m/$1 [P]
    </IfModule>

    According to phpinfo(), I have mod_proxy and mod_rewrite enabled.

    From error log I get "[Thu Sep 13 16:32:55 2007] [error] [client 194.204.*.*] File does not exist: /var/www/web15/web/cms, referer: http://host1.mydomain. com/"

    What it means is that there is no url rewriting being done. I checked if .htaccess is being parsed by adding invalid characters into it and I got 500 internal error, which means .htaccess is being parsed.

    I use ISPConfig as a frontend for my virtuals. There is a texbox called "Apache Directives". For host1.mydomain. com I have filled it with:

    <Directory /var/www/web15/web/>
    Options +Includes +FollowSymlinks -Indexes
    AllowOverride All
    Order allow,deny
    Allow from all
    <Files ~ "^\.ht">
    Deny from all
    </Files>
    </Directory>

    No, I don't want to keep the contents of my .htaccess files in these small texboxes.

    cms.mydomain.co m has directives for white-listing my proxies:

    <Directory proxy:*>
    Order Deny,Allow
    Deny from all
    Allow from host1.mydomain. com, host2.mydomain. com
    </Directory>

    Here are some relevant sections from /etc/apache2/vhosts/Vhosts_ispconfi g.conf

    ############### ############### ########
    # Vhost: host1.mydomain. com:80
    ############### ############### ########
    #
    #
    <VirtualHost 195.250.*.*:80>
    <Directory /var/www/web15/web/>
    Options +Includes +FollowSymlinks -Indexes
    AllowOverride All
    Order deny,allow
    Allow from all
    <Files ~ "^\.ht">
    Deny from all
    </Files>
    </Directory>
    ServerName host1.mydomain. com:80
    ServerAdmin webmaster@mydom ain.com
    DocumentRoot /var/www/web15/web
    DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm
    ScriptAlias /cgi-bin/ /var/www/web15/cgi-bin/
    AddHandler cgi-script .cgi
    AddHandler cgi-script .pl
    ErrorLog /var/www/web15/log/error.log
    AddType application/x-httpd-php .php .php3 .php4 .php5
    <Files *.php>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php3>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php4>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php5>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    php_admin_flag safe_mode Off
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    AddType application/vnd.wap.wmlscri ptc .wmlsc .wsc
    AddType text/vnd.wap.wml .wml
    AddType text/vnd.wap.wmlscri pt .ws .wmlscript
    AddType image/vnd.wap.wbmp .wbmp
    Alias /error/ "/var/www/web15/web/error/"
    ErrorDocument 400 /error/invalidSyntax.h tml
    ErrorDocument 401 /error/authorizationRe quired.html
    ErrorDocument 403 /error/forbidden.html
    ErrorDocument 404 /error/fileNotFound.ht ml
    ErrorDocument 405 /error/methodNotAllowe d.html
    ErrorDocument 500 /error/internalServerE rror.html
    ErrorDocument 503 /error/overloaded.html
    AliasMatch ^/~([^/]+)(/(.*))? /var/www/web15/user/$1/web/$3
    AliasMatch ^/users/([^/]+)(/(.*))? /var/www/web15/user/$1/web/$3
    </VirtualHost>

    ############### ############### ########
    # Vhost: cms.mydomain.co m:80
    ############### ############### ########
    #
    #
    <VirtualHost 195.250.*.*:80>
    <Directory proxy:*>
    Order Deny,Allow
    Deny from all
    Allow from host1.mydomain. com, host2.mydomain. com
    </Directory>
    ServerName cms.mydomain.co m:80
    ServerAdmin webmaster@mydom ain.com
    DocumentRoot /var/www/web17/web
    DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm
    ScriptAlias /cgi-bin/ /var/www/web17/cgi-bin/
    AddHandler cgi-script .cgi
    AddHandler cgi-script .pl
    ErrorLog /var/www/web17/log/error.log
    AddType application/x-httpd-php .php .php3 .php4 .php5
    <Files *.php>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php3>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php4>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>
    <Files *.php5>
    SetOutputFilter PHP
    SetInputFilter PHP
    </Files>

    I have no clue what could be wrong, I have Googled a whole day, trying everything out with no results :(
  • jaanus
    New Member
    • Sep 2007
    • 3

    #2
    Seems like mod_proxy is being used by mod_rewrite.
    mod_rewrite can be used in htaccess files while mod_proxy cannot. I moved apache directives into apache main configuration files and now the requests are being redirected.

    New problem has risen though. I get the following error:

    "[Thu Sep
    13 23:10:56 2007] [error] [client 194.204.*.*] client denied by
    server configuration: proxy:http://www.mydomain.co m/example.js,
    referer: http://host1.mydomain. com/"

    Comment

    • jaanus
      New Member
      • Sep 2007
      • 3

      #3
      Already found a solution.

      Comment

      Working...