Link to home
Start Free TrialLog in
Avatar of majdolyan
majdolyanFlag for Saudi Arabia

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
Avatar of Michael701
Michael701
Flag of United States of America image

you should just have to add http://www.essoog.com/ to your header ('location: '.http://www.essoog.com/.'whatever else you have....');

post your redirection code if you require more help
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]

Open in new window

typo,
R is statuscode 302
R=301 is 301 of course.
Avatar of majdolyan

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=XXXX

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.
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.
> 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.
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
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]

Open in new window

Thanks but this didn't work, other subdomains still ignore the cpanel redirect.
Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial