Aargh, need help with mod-rewrite

Discussion in 'Apache' started by tigs, Jul 10, 2006.

  1. #1
    i have the following .htaccess file in an addon domain:

    # Prevent this file being read
    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    # Prevent directories being displayed
    Options -indexes
    # Specify error handling routines
    ErrorDocument 400 /error.php
    ErrorDocument 401 /error.php
    ErrorDocument 402 /error.php
    ErrorDocument 403 /error.php
    ErrorDocument 404 /error.php
    ErrorDocument 500 /error.php
    RewriteEngine on
    RewriteRule iz/autowebbus http://www.myaddondomain.com/iz/index.php?site=gyp&page=autobus [R=301,L]
    RewriteRule iz/adcopysecrets http://www.myaddondomain.com/iz/index.php?site=gyp&page=adcopy [R=301,L]
    RewriteRule iz/adsense http://www.myaddondomain.com/iz/index.php?site=cbank&page=adsense [R=301,L]
    RewriteRule iz/clickrich http://www.myaddondomain.com/iz/index.php?site=cbank&page=clickrich [R=301,L]
    RewriteRule iz/golf http://www.myaddondomain.com/iz/index.php?site=howto&page=golf [R=301,L]
    RewriteRule iz/mindmotivators http://www.myaddondomain.com/iz/index.php?site=cbank&page=mindmotivators [R=301,L]
    RewriteRule iz/mjoyner http://www.myaddondomain.com/iz/index.php?site=cbank&page=mjoyner [R=301,L]
    RewriteRule iz/newstk http://www.myaddondomain.com/iz/index.php?site=howto&page=newstk [R=301,L]
    RewriteRule iz/prestk http://www.myaddondomain.com/iz/index.php?site=howto&page=prestk [R=301,L]
    RewriteRule iz/sizzle http://www.myaddondomain.com/iz/index.php?site=cbank&page=sizzle [R=301,L]
    RewriteRule iz/thirtydayprofits http://www.myaddondomain.com/iz/index.php?site=cbank&page=thirtydayprofits [R=301,L]
    RewriteRule iz/totfrcar http://www.myaddondomain.com/iz/index.php?site=cbank&page=totfrcar [R=301,L]
    RewriteRule iz/wdstotfc http://www.myaddondomain.com/iz/index.php?site=cbank&page=wdstotfc [R=301,L]
    RewriteRule iz/howto(.*)$ http://www.myaddondomain.com/iz/index.php?site=howto&page=$1 [R=301,L]
    RewriteRule iz/marlon(.*)$ http://www.myaddondomain.com/iz/index.php?site=gyp&page=$1 [R=301,L]
    RewriteRule iz/[^/]*/(.*)$ http://www.myaddondomain.com/iz/index.php?site=$1&page=$2 [R=301,L]
    RewriteRule [^/]*/(.*)$ http://www.myaddondomain.com/$1/index.php?site=$2 [R=301,L]

    the top domain has this .htaccess file:

    # Prevent this file being read
    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    # Prevent directories being displayed
    Options -indexes
    # Allow rss
    AddType application/rss+xml .rss
    # Specify error handling routines
    ErrorDocument 400 /errorfiles/400.php
    ErrorDocument 401 /errorfiles/401.php
    ErrorDocument 402 /errorfiles/402.php
    ErrorDocument 403 /errorfiles/403.php
    ErrorDocument 404 /errorfiles/404.php
    ErrorDocument 500 /errorfiles/500.php
    # Redirect sites to new urls
    Redirect 301 /the-first-site/ http://www.the-first-site.com/
    Redirect 301 /the-second-site/ http://www.the-second-site.co.uk/
    Redirect 301 /the-third-site/ http://www.the-third-site.co.uk/
    Redirect 301 /the-fourth-site/ http://www.the-fourth-site.co.uk/
    Redirect 301 /the-fifth-site/ http://www.the-fifth-site.co.uk/
    #Redirect 301 mytopdomain.com/index.html #http://www.mytopdomain.com/index.php
    Redirect 301 /the-sixth-site/ http://www.the-sixth-site.co.uk/
    Redirect 301 /misclinks.html http://www.mytopdomain.com/misclinks.php
    Redirect 301 /busoplinks.html http://www.mytopdomain.com/busoplinks.php
    Redirect 301 /svcslinks.html http://www.mytopdomain.com/svcslinks.php
    Redirect 301 /svcslinks2.html http://www.mytopdomain.com/svcslinks2.php
    Redirect 301 /the-seventh-site/ http://www.the-seventh-site.co.uk/
    Redirect 301 /the-eighth-site/ http://www.the-eighth-site.co.uk/
    Redirect 301 /the-ninth-site/ http://www.the-ninth-site.co.uk/
    Redirect 301 /the-tenth-site/ http://www.tenth.co.uk/
    # Prevent non-www version causing 'duplicate pages'
    RewriteEngine on
    #RewriteCond %{HTTP_HOST} !^www\.mytopdomain\.com
    #RewriteRule (.*) http://www.mytopdomain.com/$1 [R=301,L]

    [Some of these commands have had to be disabled, because of the nature of the
    top domain/addon domain relationship.]

    i am using the following url:
    http://www.myaddondomain.com/ysf/esuccess

    when processed by an .htaccess file in the root of addon domain:
    myaddondomain.com (which means that "http://www.myaddondomain.com/" is ignored)

    containing this command:
    RewriteRule [^/]*/(.*)$ http://www.myaddondomain.com/$1/index.php?site=$2 [R=301,L]

    mod rewrite should do this:
    store the part of the calling url up to the first / in a variable called $1 (ignoring http://www.myaddondomain.com/);
    store the part of the calling url after the first / in a variable called $2;
    rewrite the url as follows:
    http://www.myaddondomain.com/{contents of $1, that is "ysf"}/index.php?site={contents of $2, that is "esuccess"};
    it should then stop processing (L in square brackets at the end means that, if this command is processed, it is the last command);
    send a 301 header;
    load the page with the rewritten url.

    However, it is resolving to:
    http://www.myaddondomain.com/ysf/index.php?site=index.php

    instead of:
    http://www.myaddondomain.com/ysf/index.php?site=esuccess



    when i changed the command to:
    RewriteRule [^/]*/(.*)$ http://www.myaddondomain.com/$1/index.php\?site=$2 [R=301,L]

    the destination url changed to:
    http://www.myaddondomain.com/index.php/index.php?site=



    has anyone any ideas, please?
     
    tigs, Jul 10, 2006 IP