mod-rewrite

RewriteCond not matching?


I've read several url rewriting posts but nothing that helped me.

Basically on the website we have pages ending with ".html" (http://www.domain.com/page.html), and we also keep some other subdomains stuff (http://www.domain.com/subdomain.com)

So I'm trying to get this: http://www.domain.com/subdomain.com to be redirect to: /www/subdomain.com/index.php

I tried this but there's something wrong with it:

RewriteCond %{QUERY_STRING} !\.html$
RewriteCond %{QUERY_STRING} ^([^/.]+)\.([^/.]+)/?$
RewriteRule /www/%1.%2/index.php [L]

I think I'm misunderstanding the RewriteCond usage but I can't find out how to do it properly. What am I missing?

Thanks, Rob


Solution

  • This should solve your URL rewriting needs:

    RewriteCond %{QUERY_STRING} !\.html$
    RewriteRule ^([^/.]+)\.([^/.]+)/(.*) /www/$1.$2/index.php?file=$3 [QSA,NC,L]
    

    For debugging on your own server, add:

    RewriteLog "/web/logs/mywebsite.rewrite.log"
    RewriteLogLevel 9
    RewriteEngine On
    

    Useful resources: