Forum Moderators: phranque

Message Too Old, No Replies

Help with simple subdomain rewrite

         

Tusserte

10:34 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



Hello everyone, I was wondering how to get a simple mod_rewrite so that username.action.example.com = example.com/action=username, where the username is dynamic, and the action is just a name for some page that I want to set up. Here is the code I have tried, but it does not work. Can anyone help me? Thanks for your time.

NOTE: I have already written Options +FollowSymlinks and RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)\.profiles\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/profiles.php?name=%1 [L]

[edited by: jdMorgan at 12:30 am (utc) on Sep. 19, 2008]
[edit reason] example.com [/edit]

g1smd

12:04 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Although the [L] suggests you want a rewrite, the included domain name gets you a 302 redirect.

What do you want; a redirect or a rewrite?

Tusserte

12:20 am on Sep 19, 2008 (gmt 0)

10+ Year Member



I guess I'm not quite clear on the syntax. I want the page to not redirect, so that when you visit username.action.mysite.com it will still look like username.action.mysite.com but will actually be displaying mysite.com/action=username. I guess that makes it a rewrite, unless I am more confused than I thought.

jdMorgan

12:29 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove the http method and the domain name from the substitution, using only the filepath from root.

Is this code in .htaccess, or in httpd.conf?
If in .htaccess, are you sure that all subdomains have this .htaccess file's directory as their DocumentRoot?
Please define "doesn't work."
How did you test?
What were the results?
How did the results differ from your expectations?
Anything in your server error log?

Jim

Tusserte

12:37 am on Sep 19, 2008 (gmt 0)

10+ Year Member



Quick note: On my current host I currently have only one active folder (the /public_html/ folder) which contains all of my files for now. I am using a .htaccess file inside this folder, and it is the only .htaccess file on the site. To test the subdomain, I'd type in fdsa.profile.example.com and see if the page showed up or not. At this point, nothing would happen no matter what the $_GET is. I'm just hoping that the page would show up blank instead of giving me the Firefox "Page Load Error" message. I clear my cache and try the page, and I still get the "Page Load Error" message as if the site doesn't exist (but the regular www subdomain does still work). I'm using cPanel, and I'm not too familiar with the Error Log but I don't think there's anything mentioning the subdomain not working right now.

jdMorgan

1:11 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you modified your DNS zone file to define these new subdomains? From your description of the error, it sounds like you have not. You should define the subdomain as

*.profile.example.com. A 123.45.67.89

or

*.profile.example.com. CNAME example.com

Note the trailing period on the domain -- It is required.

Jim

jdMorgan

1:16 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And to continue that thought...

It will take anywhere from four hours to several days before these new subdomains resolve to your server -- It takes time for the updated zone file to propagate world-wide, to every ISP, etc.

Next, you'll need to be sure that your server knows where to send requests for these subdomains. Hopefully, your control panel can be used to point them all to your main folder, but this is not always the case. In some cases, it won't let you define subdomains (sorry, pay extra), and in others, it points them to a subdirectories of your main filespace, and there is no choice about that. And it may not be possible to define the "wildcard" sub-sub-domain that you intend to put the username into, and that means that you will then have to use the control panel to define each and every user account -- In short, you'll need a better/more flexible host at that point...

Jim