Forum Moderators: phranque
Right now I'm using this code to restrict users from going to [mydomain.com...] as I want them to enter through [sub.mydomain.com....]
RewriteEngine On
RewriteCond %{HTTP_HOST}!sub.mydomain.com [NC]
RewriteRule .* /index.php
I'd like to redirect a user to the page they are trying to reach through the "invalid" method.
For example:
When a user tries to access through an outside link:
[mydomain.com...]
I'd like to redirect them to that file, but through this method:
[sub.mydomain.com...]
I can do this with PHP, but I really don't know .htaccess. Can anyone help me with this or point me to some understandable .htaccess documentation?
Thanks.
Welcome to WebmasterWorld!
RewriteEngine On
RewriteCond %{THE_REQUEST} !http://sub\.mydomain\.com [NC]
RewriteRule ^([^/]+)/(.*)$ http://$1.mydomain.com/$2 [R=301,L]
You may want to add more code to validate that "xyz" *is* a valid subdomain before redirecting. You may also want to exclude this rewriting if the "www" subdomain is requested.
See "back-references" in the RewriteRule documentation (see links in our forum charter).
Jim
I'm sorry, I may be a bit too tired right now to give a helpful answer, but perhaps this thread [webmasterworld.com] about subdomains would be worth checking out?
(didn't get a response from that guy yet though, but that should probably indicate it works :) ..or that things take time)
-Eivind