Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite to determine subdomain and redirect

         

hershko

2:53 pm on May 12, 2005 (gmt 0)

10+ Year Member



i have no idea how to do this, but i'm told i can do it with mod_rewrite

users on my site will get their own subdomain username.mydomain.com

i need to redirect that url to www.mydomain.com/subdir/username/

so my question is how do i use mod_rewrite so that whatever subdomain (username) is entered into the url will be picked up and redirected to the appropriate subdirectory?

i understand i have to place a .htaccess file in the root directory, but how do i code this?

thanx!
o

jdMorgan

6:31 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hershko,

Welcome to WebmasterWorld!

This subject has been pretty well-covered here. I suggest doing a search [google.com] and reading those threads as well as the references cited in our charter [webmasterworld.com].

Mod_rewrite is not something that you can just cut-n-paste with any success, so a bit of studying/learning is most probably going to be required.

Jim

jd01

6:35 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi hershko,

If you really have no ideas on mod_rewrite, I suggest reading this, so you have an idea of the answer you will get:

[webmasterworld.com...]

Then when you have an idea, this one seems to address the specific question you are asking:

[webmasterworld.com...] (This may not be the one I was thinking, if it does not help, Please follow Jim's suggestion... We were posting at the same time =).)

When you are done with those, take your best guess and we'll help you from there.

Hope this gives you some ideas.

Justin

hershko

5:27 pm on May 19, 2005 (gmt 0)

10+ Year Member



below is the current .htaccess file i found in my root web directory. what line do i need to add so that each invalidsubdomain.example.net will redirect to www.example.com/blog/invalidsubdomain

thanx!
ohad

--------

Redirect permanent /mail [example.com...]

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^https://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.example.com$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ http://www.example.com [R,NC]

[edited by: jdMorgan at 10:47 pm (utc) on May 19, 2005]
[edit reason] Examplified. [/edit]