homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite subdomain
subdomain rewrite

 8:56 pm on Dec 8, 2012 (gmt 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)

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)

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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved