Forum Moderators: phranque
thanks in advance. :)
-----------------------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.webmasterworldsite\.dom
RewriteRule (.*) [%1.webmasterworldsite.dom...] [R=301,L]
#
RewriteCond %{REQUEST_URI}!^/mypage\.php
RewriteCond %{HTTP_HOST}!^www\.webmasterworldsite\.dom
RewriteCond %{HTTP_HOST} ^([^.]+)\.webmasterworldsite\.dom
RewriteRule ^$ /mypage.php?%1 [L]
#
RewriteCond %{HTTP_REFERER}!^http://webmasterworldsite.dom/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://webmasterworldsite.dom$ [NC]
RewriteCond %{HTTP_REFERER}!^http://webmasterworldsite2.dom/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://webmasterworldsite2.dom$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.webmasterworldsite.dom/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.webmasterworldsite.dom$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.webmasterworldsite2.dom/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.webmasterworldsite2.dom$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} !^/mypage\.php
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* /mypage.php?%1 [L]
#
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2\.com [NC]
RewriteRule \.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]
The pattern ^$ in your second rule has been changed to .* to allow all files in the subdomain to be rewritten.
The last two rules above replace all eight of your image-blocking rules, and avoid the problem of appended port numbers breaking your original rules.
Replace all broken pipe "¦" characters above with solid pipe characters from your keyboard before trying to use this code.
Jim
but the code still didn't work. I contacted the host support and they say that mod_rewrite works on all the server. we are on a shared hosting.
I replaced the broken pipes to solid pipes and change the domain names on the script and uploaded it, nothing happened. I also tried removing the first line but still didn't work. I check the php script using mypage.php?username and the script is working.
if I type [username.example.com...] the error message is "username.example.com cannot be found, please check the name and try again."
I also tried several pattern from drbacchus rewrite cookbook but it did't work. :(
thanks for the help.
Note that you can define them one-by-one, or simply define a wild-card subdomain and specify the IP address of your server.
Jim
Going back to first principles, have you modified or added records to your DNS zone file to *define* these subdomains? And will your host recognize them and deliver them to your "account"?
where can I find the DNS zone file? I have hundreds of users, should i define each of them inside the DNS zone file that you mentioned?
thanks for the patience.
It is not clear whether you have any existing subdomains other than "www" defined. If you have several and you did not manually create them, then you probably don't have to worry about the zone file, because the existence of these subdomains would indicate that you've already got wild-card DNS set up. However, the error message you posted above argues against that.
If you intend to "automatically" redirect subdomains to subdirectories, don't use cPanel. Doing so would require you to manually create each subdomain and a subdirectory to host it.
You might want to try a few searches for "wild-card DNS" here on WebmasterWorld and on the Web at large. You may find a decent tutorial by doing so.
Jim
Ask your host how you can access your DNS zone file.
It is not clear whether you have any existing subdomains other than "www" defined.
If you intend to "automatically" redirect subdomains to subdirectories, don't use cPanel.
I'll wait for the reply of my host and research on the wild-card DNS.
Many thanks! :)
403 Forbidden
You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.33 Server at www.**********.com Port 80
It seems that the host don't give rights on the dns zone file and they're the one who setup the wild-card dns (as they say). I tried using several pattern again up to the point that the site gives "too many redirection" error but I can't really do it and restored the original back to your script that you gave.
The host also said that I should wait for the propagation of the DNS and I should check the mod_rewrite script if it is working properly, but I don't know how to check it (use it on another site?)
thanks sir!
Looking at the code, the second and third rulesets should be exchanged as shown below. This would not have caused the error you are seeing, but will prevent image requests from invalid referrers from being rewritten to your mypage.php script. You'll also need to allow for blank referrers, as discussed many times in hotlinking threads in this forum.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2\.com [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F,NC]
#
RewriteCond %{REQUEST_URI} !^/mypage\.php
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* /mypage.php?%1 [L]
Jim
Forbidden
You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.33 Server at www.********.com Port 80
I assume the "/" is the root.
I just notice that if you type
example.dom/anythinghere -> will give blank page
username.example.dom -> will give 403 and 404 error
username.example.dom/anythinghere -> will give you blank page
I'll email the host and ask if they can check the wild-card dns again.
thanks again.
Copy your .htaccess file to a backup, and then delete .htaccess from your top directory. Put a dirt-simple "index.html" file in your home directory if none exists -- plain HTML and no scripts.
Now access your domain, www subdomain, and other subdomains. If your host has set up your acccount properly, you should see the same index.html page for each request. If not, write them, tell them you deleted .htaccess, and it still does not work.
Jim
I did just what you just said.
1.) deleted .htaccess
2.) put in index.html
3.) access bbb.example.com - Error 403
4.) access www.example.com - blank html appeared
5.) access www.bbb.example.com - Error 403
I put back the original index.php, now my site runs without it.
but the username.example.com still got error 403.
should I report to the host about it?
thanks again.
Jim