Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite Need Help Please!

         

shinsan

1:43 pm on Jan 19, 2011 (gmt 0)

10+ Year Member



Hi There


I have a website

www.domain.com

that will have multiple users that will each be able to type in there own domain

e.g. company.domain.com,

I want it that when they type in there domain it goes to

e.g. www.domain.com?company=company

is this possible or do I have to create a subdomain for each user

jdMorgan

12:05 am on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you have to set up a subdomain for each user in DNS and at the server configuration level.

If you are on shared name-based hosting, this may not be possible -- or there may be limits to how many subdomains you can create and little or no flexibility in how those subdomains are mapped into the server's filesystem. The simplest solution is to use IP-based virtual hosting, which costs about $1.00 more per month in the U.S., and can give you complete control over your DNS configuration and the server's hostname-to-filespace mapping.

That is the difficult part. After that, it requires only a two-line mod_rewrite rule to map requested hostnames to a query string value.

Jim

shinsan

5:31 am on Jan 20, 2011 (gmt 0)

10+ Year Member



I have my url with yahoo and all subdomain direct to my dedicated server using wildcard e.g.
"*.mydomain.com" is automaticaly directed to my server IP so if I try to browser to *.mydomain.com I get this message.

"Directory Listing Denied

This Virtual Directory does not allow contents to be listed."

so I think all I need is to mod-rewrite to the correct url right now I have this


RewriteEngine On
RewriteCond %{HTTP_HOST} !^w{3}\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.tripspyder\.com$ [NC]
RewriteRule ^/$ /home.php?company=%1 [L]


any help will be appreciated thanks

jdMorgan

9:17 pm on Jan 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aside from a few problems when non-canonical hostnames are requested and the inefficient pattern in the first rewritecond (a simple "!^www\. " would be shorter/better), that code should work as intended if placed in your httpd.conf file, as long as it is not enclosed in a <Directory> section.

So where did you put this code to test it?

Jim

shinsan

8:31 am on Jan 25, 2011 (gmt 0)

10+ Year Member



This is my rewitre rules I have now and it was working but images were not comming up, and now it is'nt working at all >>


RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?[a-z0-9-].domain.com [NC]
RewriteRule (.*) http://www.domain.com/home.php?company=%2 [L,P]



What Im trying to do exactly is reuqest a users page by typing in

companyname.domain.com of which rewrites this


www.domain.com/home.php?comany=companyname

but in the urls bar of the browser it still has

companyname.domain.com but instead it was rewriting

companyname.domain.com/home.php?comany=companyname with my rewrite code as

RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?[a-z0-9-].domain.com [NC]
RewriteRule (.*) home.php?company=%2 [L]




but with

RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?[a-z0-9-].domain.com [NC]
RewriteRule (.*) http://www.domain.com/home.php?company=%2 [L,P]


was working and showed companyname.domain.com in the url bar but images were not showing up .


companyname.domain.com/home.php?comany=companyname
gives me an error because I don't have a website on my server with that name setup I just want it to get this url instead

www.domain.com/home.php?comany=companyname

OW and by the way Im using IIS and a software called IIS Mod-Rewrite from here [micronovae.com ]

your help is greatly appreciated

thank you

shinsan

9:51 am on Jan 25, 2011 (gmt 0)

10+ Year Member



OK it woking now but like I said images are not show no why that may be ?

g1smd

10:09 am on Jan 25, 2011 (gmt 0)

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



In your code you say was working %2 will always be "undefined".

shinsan

10:18 am on Jan 25, 2011 (gmt 0)

10+ Year Member



Why I don't get Please explain .

shinsan

10:24 am on Jan 25, 2011 (gmt 0)

10+ Year Member





RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) http://www.domain.com/home.php?company=%2 [L]


This also works but the url changes in the browser to
http://www.domain.com/home.php?company=comanyname

g1smd

10:34 am on Jan 25, 2011 (gmt 0)

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



In this code, %2 will be defined because you now have two sets of parentheses.

The URL changes because the code produces a 302 redirect to a new URL.

shinsan

10:39 am on Jan 25, 2011 (gmt 0)

10+ Year Member



how do Im make the url stay as companyname.domain.com in the browser Please help me correct it.

thank you

shinsan

2:33 am on Jan 27, 2011 (gmt 0)

10+ Year Member



Iv've fix it now thanks I just did this

RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule ^/(.*)/(.*\.jpg|.*\.png|.*\.gif|.*\.css|.*\.js|.*\.mov|.*\.wmv|.*\.pdf)$ http://www.domain.com/$1/$2 [L]

RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule ^/(.*\.jpg|.*\.png|.*\.gif|.*\.css|.*\.js|.*\.mov|.*\.wmv|.*\.pdf)$ http://www.domain.com/$1 [L]

# for Redirecting anything.domain.com/nothing can be here
RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule ^/$ http://www.domain.com/home.php?company=%2 [P]

RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^[a-z0-9-]+\.domain\.com [NC]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/(.*\.php)$ http://www.domain.com/$1?%1 [P]

g1smd

8:30 pm on Jan 27, 2011 (gmt 0)

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



You need to escape every literal period in every RewriteCond pattern (you missed almost half of them).

The pattern can be much simplified:
^/([^/]+)/([^.]+\.(jpe?g|png|gif|css|js|mov|wmv|pdf))$