Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Wildcard DNS and mod rewrite?
Old 04-25-2007, 12:45 PM Wildcard DNS and mod rewrite?
Novice Talker

Posts: 12
Trades: 0
I have several sub domains where it may be easy to mistype. I therefore setup a wildcard DNS so my site catches everything with my domain. The problem is I want to alert people they made a mistake. Currently the wildcard sends you to my homepage but I would like to make an “error” page letting people know they should check their typing.

Can this be done?

Thanks
johnnyk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-25-2007, 02:54 PM Re: Wildcard DNS and mod rewrite?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,371
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep, but it will need to be in server side code. You would check for the value of HTTP_HOST then action accordingly
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-25-2007, 07:56 PM Re: Wildcard DNS and mod rewrite?
Novice Talker

Posts: 12
Trades: 0
This is what I have so far:

I use this to get rid of the www on everything:

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


This is what I am attempting to use to get the non (mistyped / catch all) subdomains to go to:

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\..+\..*$ [NC]
RewriteRule ^(.*)$ http://www.yourwebsite.com/errors/error.php [L,NS]


The top code works great by itself but the bottom code causes a 500 internal server error. I was also told that the code below may work but as a novice I have no idea what it means.







# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]



Any pointers or help greatly appreciated.

Thanks
johnnyk is offline
Reply With Quote
View Public Profile
 
Old 04-25-2007, 08:03 PM Re: Wildcard DNS and mod rewrite?
Novice Talker

Posts: 12
Trades: 0
Oops, as a newbie I don’t think any of my code is server side? Can you guys point me in the right direction or does anyone have server side code that does this?

Thanks again,
John
johnnyk is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Wildcard DNS and mod rewrite?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.48534 seconds with 12 queries