Forum Moderators: phranque
I'm having problems using real and virtual subdomains.
I have created virtual subdomains with wildcards like:
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example.net
RewriteCond %{REQUEST_URI}!^/%1/
RewriteRule (.*) file_on_server/%1/ [nc] This is working properly.
But, today created a real subdomain in Cpanel (http://s.example.net) and when type this, redirects to the main website [s.example.net...] ('intro' is another rewrite rule in the same htaccess).
The Zone File looks like:
* - 14400 - CNAME - example.net.
s - 14400 - A - MyIP
www.s - 14400 - A - MyIP
Everything is working fine, except the "s" real subdmain.
I tried to disable the virtual subdomains in htaccess to see what happen, but it doesn't work as expected :?
Any ideas on what is happening here?
Thanks in advance :)
RewriteCond %{REQUEST_URI} !^/%1/ [nc]
A better approach might be to do this:
RewriteCond %{REQUEST_URI} [b]!^/sub_[/b]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.net
RewriteRule (.*) /[b]sub_[/b]%1/$1 [L]
The "sub_" prefix shown here is arbitrary; You can use any sufficiently-unique string that you like.
Jim
I changed the rule but it still doesn't work, also I deleted everything inside the htaccess to see if this is the problem, but continues redirecting to the main website, not to the directory view.
Can be the zone file or Apache config the problem?
The new rule looks (some changes based on your rewrite rules in other posts):
RewriteCond %{HTTP_HOST}!^(www¦s)\.example\.net [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([0-9a-z]+)\.example\.net [NC]
RewriteRule ([0-9]+)? dir/file.php?id=%2&page=$1 [L] Thanks for your help!
That's a good clue right there, because the code we are discussing doe not redirect, it does an internal rewrite. You should see no change in the browser address bar. If you do, then this code is not at fault -- Code in a higher-level .htaccess file, or in httpd.conf is interfering or is unconfigured or misconfigured.
Also, please don't make unrelated code changes until we get this working -- changing things around only confuses things. I don't know what (www¦s) is intended to do, but let's not complicate things. Also, do not use [NC] unless you want to have major problems with independently-existing upper- and lower-case subdomains and subdirectories -- I suggest you accept only lowercase, and therefore, the [NC] flags should be omitted.
Jim
The currently htaccess looks like:
Options +FollowSymlinks
RewriteEngine onRewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(www\.)?([0-9a-z]+)\.example\.net
RewriteRule ([0-9]+)? dir/file.php?id=%2&page=$1 [nc]
RewriteRule ^cover/?$ dir/index.php [nc]
So, in "/index.php" tells the browser to go to "http://www.example.net/cover/".
When I created the real subdomain "http://s.example.net" *redirects* to "http://s.example.net/cover/"
Do you think the hosting admin misconfigured the httpd.conf?