Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite not working for some domains

         

test1

8:20 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



I have a mod rewrite rule that allows my users to add a custom domain to their site and then I use that domain name to look up what their user information is. This has been working fine but for some reason it looks like it doesn't work potentialy if there is a number in the domain name. Can someone take a look at what I have and let me know what the issue might be?

RewriteCond %{HTTP_HOST} ^(www\.)?([a-z][a-z0-9\-]+\.[a-z]{2,4}(\.[a-z]{2})?)

The domain in questions has a number followed by a word so something like "6mydomain.com".

jdMorgan

8:47 pm on Nov 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Modified to allow numbers in domain names, expand and correct tld checking for new TLDs (such as .name and .museum, to make checking of .co.cc TLDs more explicit, to recognize and allow FQDNs and appended port numbers (but discard the extra characters), and to end-anchor the pattern to prevent sneaky-user tricks) :

RewriteCond %{HTTP_HOST} ^(www\.)?(([a-z0-9][a-z0-9\-]+\.)+(co\.[a-z]{2}¦[a-z]{2,6}))\.?(:[0-9]+)?$

As an example, this rule will accept www.good-4u-apples.365-day-fruits.co.uk.:80 (which is a perfectly-valid hostname) and the resulting $2 variable that you likely use in the RewriteRule following this RewriteCond will then contain "good-4u-apples.365-day-fruits.co.uk"

Change the broken pipe "¦" character to a solid pipe character before use; Posting on this forum modifies the pipe characters.

This recoded RewriteCond assumes that you are using only $2 to back-reference the requested hostname and TLD, stripped of any leading "www.". If you were using other back-references to refer to any of the pieces and parts of the requested hostname, they may be broken by the the changes in the parentheses used in this new pattern; Those back-references will need to be adjusted.

Jim

test1

8:51 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



Wow, very awesome job. I was just expecting a suggestion but this is great. I'll try it out and let you know.

test1

8:56 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



It works great! Thanks for not only fixing but greatly improving what I had. Excellent job!

g1smd

2:57 am on Nov 18, 2008 (gmt 0)

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



i often find that the problem I want to fix has other parts to it that only become apparent after the first attempt at cracking the problem. :-)

There's a heck of a lot of things that are going to break when TLDs with more than three or four letters become more common.

A lot of email scripts and response forms will reject such email addresses as non-valid for example.

As for the web... it could be "interesting".

test1

8:48 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



Sorry to bother you again, but I just noticed that if someone tries to add a domain name with a hyphen in it that it no longer works. Are there any other puncuation marks that you can think of that are valid in domain names but aren't covered by this? Thanks again for all the help thus far.

g1smd

12:20 am on Dec 3, 2008 (gmt 0)

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



Other than "non-ASCII" characters in the Far-East, Asia, and such like, I can't think of any punctuation.

jdMorgan

12:14 am on Dec 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The original RewriteCond I posted specifically allows hyphens in the subdomain, but I did notice that it would also allow a hyphen as the final character of the subdomain -- something which is not valid according to the HTTP specification. So I'd suggest making a small change:

RewriteCond %{HTTP_HOST} ^(www\.)?(([a-z0-9][a-z0-9\-[b]]*[a-z0-9][/b]\.)+(co\.[a-z]{2}¦[a-z]{2,6}))\.?(:[0-9]+)?$

This doesn't do anything to correct the problem you reported, though. Please re-check that, and if you still have a problem after completely-flushing your browser cache, then please post the entire rule --both the RewriteCond(s) and the associated RewriteRule-- so we can see the whole picture.

Jim

test1

4:13 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Jim,

Thanks for the reply. After looking at the code and doing some testing I found that the issue was not the hyphen. One of my users was doing a URL frame which is why the htaccess file wasn't even picking up the domain name in the first place.

Thanks again for the help.

test1

9:06 pm on Dec 31, 2008 (gmt 0)

10+ Year Member



Any ideas on how I could use named anchors in the url? Right now they are pretty much ignored. I'm guessing I could just find everything after the # and pass it to the new url?

g1smd

9:28 pm on Dec 31, 2008 (gmt 0)

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



Named anchors don't leave the browser. They are for resolving a link to a position within a page. The # part isn't sent to the server as any part of the request (as far as I am aware).

coopster

10:29 pm on Dec 31, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Correct.
Previous discussions:
[webmasterworld.com...]

test1

6:05 pm on Jan 29, 2009 (gmt 0)

10+ Year Member



Jim,

Would the code I have above in theory work for domains that have mutliple endings? For instance mydomain.com.au?