Forum Moderators: phranque
In a domain example.com I need to make special redirections like follows, for [xyz.example.com:...]
1- If xyz looks like "Z123456" (Letter Z plus various digits), run a script located in domain.com/script.pl, passing xyz as data to the script.
(https://example.com/script.pl?data=xyz)
2- If xyz does not look like described above, process like for a usual subdomain xyz.domain.com (goto, or error if the subdomain does not exist).
The server runs CentOS 5 last release and Apache last release, with Plesk last release too :)
I assume it is possible with .htaccess, but really don't know how to do, reading this forum (and a few others) didn't help me :(
Thank you,
Anatoli
[edited by: jdMorgan at 5:42 pm (utc) on Oct. 4, 2009]
[edit reason] example.com and formatting tidied [/edit]
Please see our Apache Forum Charter [webmasterworld.com] for links to useful tutorials and for information about how to get the most from this forum.
Using Apache mod_rewrite, you will need to examine SERVER_PORT in a RewriteCond for the value "443" to determine that this is an HTTPS request. You will need to examine the requested hostname in HTTP_HOST using a second RewriteCond to determine that it starts with a "Z" and is otherwise composed of digits, and to capture that requested subdomain name if so.
If the request passes both of those tests, you will then rewrite the request to your script, passing the subdomain-name captured by the RewriteCond pattern to your script as a query string parameter. This is not particularly difficult -- with a little effort. It requires at most two lines of 'setup' plus two RewriteConds and one RewriteRule -- Five lines of code at most.
[added] Also make sure that your SSL certificate covers all subdomains... Most do not, and you will need to upgrade and re-install your certificate if it does not currently cover all subdomains. [/added]
Thanks,
Jim