Welcome to WebmasterWorld Guest from 54.205.75.60

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

how to parse digit in url using .htaccess?

   
6:28 am on Dec 27, 2006 (gmt 0)

5+ Year Member



Hi 2 all,

i want to use subfolders to work like subdomains

i have setup wildcard dns.

and set some .htaccess code

and all working fine.

recently i faced new problem in wildcard dns. if some one made folder which consist one more digit (i.e. just4you.domain.com) then it is redirected to domain.com.

my htaccess code is :
-------------------------------------------------
RewriteCond %{HTTP_HOST} ^([^.]+).domain.com
RewriteRule (.*) /%1/$1 [L]
-------------------------------------------------

so i want to parse digit in url and if so then it will be redirected to given subdomain.

if anyone knows this stuff then please help me ASAP

THANKS,
-ENIL

6:35 am on Dec 27, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There is nothing in your code to prevent it from working with letters, digits, or any other valid domain characters except a period/dot/full stop. It is possible that your host server configuration or a higher-lever .htaccess file is interfering with your code.

However, I'm surprised that you are not having problems with an 'infinite' redirection loop. If you are, this recent thread [webmasterworld.com] demonstrates a solution.

Jim

6:42 am on Dec 27, 2006 (gmt 0)

5+ Year Member



hi,

thanks for fast reply.

i know that i haven\'t put any condition like digit,dot etc
but i want to know how can i do that?

and i m not getting in loop. few times ago, i was caused in looping but i could get rid off looping. now this code is free from looping.

Thanks

7:01 am on Dec 27, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



This code will detect any digits in the first-level subdomain, and redirect to the "no_digits_allowed.html" page on the www subdomain.

RewriteCond %{HTTP_HOST} ^[^0-9]*[0-9][^0-9.]*\.example\.com
RewriteRule .* http://www.example.com/no_digits_allowed.html [R=301,L]

However, as long as your original code is not looping, then it should work OK with digits in the subdomain without any changes, and you should not have to use this additional code at all.

For more information, see the regular-expressions tutorial cited in our forum charter [webmasterworld.com].

Jim

6:55 am on Dec 28, 2006 (gmt 0)

5+ Year Member



Thanks for reply,

code you gave for digit parsing is not working.
it redirects example.com index file. not to the sub domain.

i used this second line instead you specified
-----------------------------------
RewriteRule (.*) /%1/$1 [L]
-----------------------------------

whenever i try to browse, it redirect to main file
i.e. suppose i try, 123.example.com then it redirects to example.com's index file. and i want it redirect to 123 folders's index file.
in short, i want this,

123.example.com => example.com/123/index.htm => in browser, path should be 123.example.com

im007.example.com => example.com/im007/index.htm => in browser, path should be im007.example.com

my previous code is working for only for alphabets. but it fails when digits are encountered and it does not redirect and page can not be found occured. previous code is:
-----------------------------------------------
RewriteCond %{HTTP_HOST} ^([^.]+).domain.com
RewriteRule (.*) /%1/$1 [L]
--------------------------------------------

pls let me know ASAP

ENIL

7:00 am on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Enil,

There is nothing wrong with your code, or with mine.

You have other rules in your server that are interfering with your code.

Or perhaps your server is mis-configured.

Jim

8:29 am on Dec 28, 2006 (gmt 0)

5+ Year Member



hi,

i now got perfect solution.

i know i have messed up the code now i got final and superb one which is perfectly working on my way. i used some part of your code.[^0-9]

here it is:
--------------------------------------
RewriteCond %{HTTP_HOST} ^([^.]+)[^0-9.]*.example.org
RewriteRule (.*) /%1/$1 [L]
--------------------------------------
no looping. no page not found error. sub domain with digit is nicely redirected.

i am very thankful to you. you provided me nice code.

Thanks again,
ENIL

[edited by: jdMorgan at 8:35 am (utc) on Dec. 28, 2006]
[edit reason] example.org [/edit]

8:38 am on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



OK, but your original code should have worked, as long as your example URLs were accurate.

I suspect that something is wrong with your server or with the regular-expressions library in your operating system.

Jim