We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Wildcard subdomain redirect

Medium Priority
997 Views
Last Modified: 2013-12-02
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
Comment
Watch Question

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
Top Expert 2008

Commented:
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

Top Expert 2008

Commented:
typo,
R is statuscode 302
R=301 is 301 of course.

Author

Commented:
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.
Top Expert 2008

Commented:
I'm wondering how ad could match the regular expression [0-9]+ which matches nothing but numbers.

Author

Commented:
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.
Top Expert 2008

Commented:
> 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.

Author

Commented:
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
Top Expert 2008

Commented:
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

Author

Commented:
Thanks but this didn't work, other subdomains still ignore the cpanel redirect.
Any other ideas?
Top Expert 2008
Commented:
Without knowing how the complete configuration (i.e. which configuration files cpanel creates and where) that's like guessing in the dark.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.