Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite subdomain

subdomain rewrite

     
8:56 pm on Dec 8, 2012 (gmt 0)

New User

joined:Dec 8, 2012
posts:2
votes: 0


mydomain.com -> www.mydomain.com

For this im using:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


www.mydomain.com/profil/myusername (RewriteRule) www.mydomain.com/profil.php?username=myusername

For this im using:
RewriteRule ^profil/([A-Za-z0-9_]+) profil.php?username=$1


In addition to above I want:

myusername.mydomain.com (RewriteRule) www.mydomain.com/profil.php?username=myusername

How do I do that?
10:58 pm on Dec 8, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12700
votes: 244


You need a RewriteCond looking at %{HTTP_HOST}. The capture will be expressed as %1 rather than $1. Let's see what you come up with; it looks as if you've got the basic knowledge already.
11:51 pm on Dec 8, 2012 (gmt 0)

New User

joined:Dec 8, 2012
posts:2
votes: 0


Well best I could come up with is:
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9_]+).%{HTTP_HOST}
RewriteRule (.*) [%{HTTP_HOST}...]

But that gave me an 500... Other attempt gave me "endless loop"....
6:41 am on Dec 9, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12700
votes: 244


Er, why do you have {HTTP_HOST} three times? You only need it once. But first detour to the post at the top of this subforum that explains why you need to use example.com.

Oh, and I now realize you will need to do some icky business with proxies (flag [P]) so your domain name doesn't turn the intended behind-the-scenes rewrite into a visible redirect.

:: detour to double-check ::

Note that the PT flag is implied in per-directory contexts such as <Directory> sections or in .htaccess files. The only way to circumvent that is to rewrite to -.

Sorry. That has nothing to do with your question. I just happened to see it, and it gave me a bit of a jolt. Like the guy who learned he'd been speaking prose all his life.