Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Wildcard subdomain redirect

Posted on 2009-02-11
11
Medium Priority
?
964 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
0
Comment
Question by:majdolyan
  • 6
  • 4
11 Comments
 
LVL 19

Expert Comment

by:Michael701
ID: 23613745
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
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23613804
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

0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23613814
typo,
R is statuscode 302
R=301 is 301 of course.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:majdolyan
ID: 23618968
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.
0
 
LVL 27

Expert Comment

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

Author Comment

by:majdolyan
ID: 23620531
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.
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23625830
> 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.
0
 

Author Comment

by:majdolyan
ID: 23627300
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
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 23627609
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

0
 

Author Comment

by:majdolyan
ID: 23629972
Thanks but this didn't work, other subdomains still ignore the cpanel redirect.
Any other ideas?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 1500 total points
ID: 23632753
Without knowing how the complete configuration (i.e. which configuration files cpanel creates and where) that's like guessing in the dark.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question