Forum Moderators: phranque

Message Too Old, No Replies

how to define the rules of the dynamic domain name?

how to define the rules of the dynamic domain name?

         

luokelong

6:00 am on Nov 29, 2011 (gmt 0)

10+ Year Member



I really need your help because I can not solve this problem.
I want to use htaccess to achieve the following functions:
Access [xyz.domain.com...] or [xyz.domain.com...] the url will be redirected to: /website.php?subdomain=xyz, and the "xyz" can not contain certain strings such as www, admin, email and so on.
Access [xyz.domain.com...] the url will be redirected to: /category.php?subdomain=xyz&cid=89
Access [xyz.domain.com...] the url will be redirected to: /document.php?subdomain=xyz&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)^[a-z0-9\-]+\.domain\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([a-z0-9\-]+)\.domain\.com/?$ /website.php?subdomain=$1

lucy24

7:43 am on Nov 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rule #1, as laid out in the Forums Charter [webmasterworld.com]: Use example.com in all your examples to prevent auto-linking. This happens in all Forums, but is especially crucial in apache because we need to see exactly what you typed. (It is not sequentially the first rule, but it is the most important.)

Converting subdomains to query strings is a pretty common question. Search through the last page or so in this Forum and you should find at least one or two examples.

Your RewriteCond as written is, uhm, gibberish. Sorry. While reading those earlier posts, you will also pick up some RegEx basics. Is the second-to-last Rule meant to be a second Condition?

luokelong

10:13 am on Nov 29, 2011 (gmt 0)

10+ Year Member



hi lucy24

thank you for your reply.

as you say the second is same to be the last condition.

I had searched some examples for this, but none of them can solve my requirement.

luokelong

10:13 am on Nov 29, 2011 (gmt 0)

10+ Year Member



the new requirement is :


Access £è£ô£ô£ð£º//£ø£ù£ú.£å£ø£á£í£ð£ì£å.£ã£ï£í or £è£ô£ô£ð£º//£ø£ù£ú.£å£ø£á£í£ð£ì£å.£ã£ï£í/, the url will be redirected to: /website.php?subexample=xyz, and the "xyz" can not contain certain strings such as www, admin, email and so on.
Access £è£ô£ô£ð£º//£ø£ù£ú.£å£ø£á£í£ð£ì£å.£ã£ï£í/category89.html, the url will be redirected to: /category.php?subexample=xyz&cid=89
Access £è£ô£ô£ð£º//£ø£ù£ú.£å£ø£á£í£ð£ì£å.£ã£ï£í/document1234.html, the url will be redirected to: /document.php?subexample=xyz&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)^[a-z0-9\-]+\.example\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([a-z0-9\-]+)\.example\.com/?$ /website.php?subexample=$1

lucy24

8:14 pm on Nov 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yurp!

:: insert boilerplate about extreme necessity of including a "charset" declaration ;) ::

What is that, Korean Windows/DOS encoding? I'm used to seeing UTF-8 or even -16 getting reinterpreted as 8859-1 but this was right off the chart. If you used www.example.com you would not have this problem because you could just write it out.

I don't see a change in your Condition(s) and Rule(s), anyway.