homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

how to parse digit in url using .htaccess?

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

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




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

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.



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


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.



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

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].



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

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



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


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.



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


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,

[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)

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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved