Monday, April 25, 2011

Help with basic .htaccess mod_rewrite.

I am currently interpreting sub-domain wild-cards with php and i would like to handle them with .htaccess, user profiles will be accessed at http://username.mysite.com/ (or for some people http://www.username.mysite.com/) which should use /main.php?action=profile

The hardest part of this is making /error/i+am+a+test+message or /files/iamatestfile.jpg go to &error=i+am+a+test+message or &files=iamatestfile.jpg

Thanks for any and all help!

From stackoverflow
  • Try:

     RewriteRule ^error/(.*) index.php?error=$1 [L]
     RewriteRule ^file/(.*) index.php?file=$1 [L]
    

    ... for the last two.

    David Zaslavsky : um... yes... just put the RewriteCond directive twice, once before each rule.
    cdmckay : Yeah, add RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] before each.
  • Try this:

    # stop rewriting for the host names example.com and www.example.com
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
    RewriteRule ^ - [L]
    
    RewriteRule ^error/(.*) index.php?error=$1 [L]
    RewriteRule ^file/(.*) index.php?file=$1 [L]
    

0 comments:

Post a Comment