majdolyan
asked on
Wildcard subdomain redirect
Hi, I have implemented the following into my website successfully.
When a user writes:
XXXX.example.com
It takes user to page:
http://www.essoog.com/index.php?page=list&uid=XXXX
But the URL stays as XXXX.example.com
I want to go one step further. I want to change the URL in the internet browser as well to http://www.essoog.com/index.php?page=list&uid=XXXX
Regards,
Majid
When a user writes:
XXXX.example.com
It takes user to page:
http://www.essoog.com/index.php?page=list&uid=XXXX
But the URL stays as XXXX.example.com
I want to go one step further. I want to change the URL in the internet browser as well to http://www.essoog.com/index.php?page=list&uid=XXXX
Regards,
Majid
Make your substitution fully qualified and add the R flag to force a redirect with th statuscode 301 or change it to R=301 for a 301 status code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([0-9]+)\.essoog\.com
RewriteRule ^$ http://www.essoog.com/index.php?page=list&uid=%1 [R,L]
typo,
R is statuscode 302
R=301 is 301 of course.
R is statuscode 302
R=301 is 301 of course.
ASKER
Hi caterham_www,
This work but it has a problem.
Now If I write any subdomain it will take redirect it to index.php?page=list&uid=XX XX
I have other predefined redirects in my cpanel which don't work now.
For example if I type ad.example.com
it will check for http://www.essoog.com/index.php?page=list&uid=ad
which is incorrect, so it will keep user in www.example.com while URL is ad.example.com
remember this wildcard is just for numbers.
This work but it has a problem.
Now If I write any subdomain it will take redirect it to index.php?page=list&uid=XX
I have other predefined redirects in my cpanel which don't work now.
For example if I type ad.example.com
it will check for http://www.essoog.com/index.php?page=list&uid=ad
which is incorrect, so it will keep user in www.example.com while URL is ad.example.com
remember this wildcard is just for numbers.
I'm wondering how ad could match the regular expression [0-9]+ which matches nothing but numbers.
ASKER
I think what happened now,
numbers will be redirected.
non-members will not be directed.
so ad.example.com
will display what www.example.com display but the URL is ad.example.com
it ignores the redirection to www.example.com/ad
I hope this helps you to understand the situation better.
numbers will be redirected.
non-members will not be directed.
so ad.example.com
will display what www.example.com display but the URL is ad.example.com
it ignores the redirection to www.example.com/ad
I hope this helps you to understand the situation better.
> it ignores the redirection to www.example.com/ad
And what should execute the redirection to /ab? It's not covered by the rule above, so your other rules present shouldn't conflict with that rule.
And what should execute the redirection to /ab? It's not covered by the rule above, so your other rules present shouldn't conflict with that rule.
ASKER
the direction for that subdomain (ad.example.com) through a cpanel subdomain redirection option and not through the .htaccess file if that makes sense ..
Regards,
Majid
Regards,
Majid
I don't know how cpanel implements subdomains, but if there's a RewriteRule above of the directory you're using this RewriteRule, this rule would opvrride previous .htaccess files. But you could use RewriteOptions inherit to avoid that -- if that's the issue.
RewriteEngine on
RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^([0-9]+)\.essoog\.com
RewriteRule ^$ http://www.essoog.com/index.php?page=list&uid=%1 [R,L]
ASKER
Thanks but this didn't work, other subdomains still ignore the cpanel redirect.
Any other ideas?
Any other ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
post your redirection code if you require more help