Help me, htacces define the rules of the dynamic domain name

I really need your help because I can not solve this problem.
I want to use htaccess to achieve the following functions:
Access http://xxxx.domain.com or http://xxxx.domain.com/, the url will be redirected to: /website.php?subdomain=xxxx, and the “xxxx” can not contain certain strings such as www, admin, email and so on.
Access http://xxxx.domain.com/category89.html, the url will be redirected to: /category.php?subdomain=xxxx&cid=89
Access http://xxxx.domain.com/document1234.html, the url will be redirected to: /document.php?subdomain=xxxx&did=1234

I tried the following rules, but only achieved the first step, the second and third steps have failed, please help me.

RewriteCond %{HTTP_HOST} (?!www|shop|bbs|home|pay|account|admin|cms|image|mobile|m|wap)[1]+\.domain\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([a-z0-9\-]+)\.domain\.com/?$ /website.php?subdomain=$1

thank you very much


  1. a-z0-9\- ↩︎

lk,

Okay, your explanation is fine (for a “specification”) so, using pseudo code:

  1. Handle the EMPTY {REQUEST_URI} string by capturing the subdomain (exclude list) and redirecting to website.php?subdomain=%1

(I don’t see that in your code so that’s one point where you need to fix your code.)

  1. THEN handle the categoryxx request by capturing the digits following category and ADDING (think QSA to retain the subdomain value) cid=$1

  2. THEN repeat step 2 for documentxx with did=$1

If you can’t translate the above and get it to work, show your translation and I’ll correct it for you (because you can only learn by trying - with guidance - and not by copying someone else’s scripts).

Regards,

DK