$15 for Wildcard subdomain .htaccess

Started on the old forum in January 2010 · view the original in the archive · old links redirect here

10 replies · 920 views · started 16 years ago · 1 min read

TL;DR · summary of 10 replies
  • WhiteWarrior provided a code snippet that could work for setting up wildcard subdomains using .htaccess.
  • krazyguy had issues with the code and needed further assistance to get it working.
  • GumSlone pointed out an error in the PHP code, suggesting it should be corrected as per their suggestion.
  • morency offered a solution for index.php that could work alongside the provided htaccess rules.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

8 participants
krazyguy Junior · 17 posts #1

I need an HTACCESS, MOD REWRITE code that will create dynamic sub-domains. The URL will need to be like this:

 [URL="http://www.user.domain.com/folder"]www.user.domain.com/folder[/URL]

will contain the content from

[URL="http://www.domain.com/store/?sub=xxx&path=zzz"] www.domain.com/xxx/?name=user&d=folder[/URL]

Payment via paypal.

ori Lead · 512 posts #2

whats ur host like vps, dedicated, shared, master reseller etc

krazyguy Junior · 17 posts #3

i have hostgator shared a/c with wildcard dns enabled

subzero Super moderator Fellow · 3,954 posts #4
        RewriteEngine on 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteCond %{HTTP_HOST} ^([^.]+).mydomain.com$ [NC] 
        RewriteRule ^([A-Za-z]+)(/)?$ index.php?customer=$1 

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

krazyguy Junior · 17 posts #5

thanks subzero i tried ur code but not working. redirecting to index page. i trid this codes too but not working.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ([^\.]+).site.(.*)
RewriteCond %{HTTP_HOST} !^wap.site.(.*)
RewriteCond %{HTTP_HOST} !^www.site.(.*)
RewriteRule ^(.*)$ index.php?id=%1 [L,NC]
</IfModule>
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.site\.com [NC]
RewriteCond %1 !^(www|wap)$ [NC]
RewriteRule ^$ index.php?id=%1 [L]

</IfModule>
GiLL Senior · 356 posts #6

i am not sure does your server host provide you correct wildcard dns setting for your domain (ask them for that you need to correct and proper wild card dns setting which need to update httpd.conf and add litle bit things in whm ) if they provide wild card dns setting you do not need to use htaccess just use this method in index.php help here

http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html

can you able to open http://test.domain.com your main page or apache success ?

$serverhost = explode('.',$_SERVER["HTTP_HOST"]);
$sub = $serverhost[0];
if ($sub = "www") {
$sub = "";
}

there are also thing you need to check every http request which will check user from mysql if user is valid and it it will send as you want or where you want else could send at main page or 404 not found as you wish

left wap stuff

GumSlone Administrator Principal · 1,690 posts #7

GiLL wrote: i am not sure does your server host provide you correct wildcard dns setting for your domain (ask them for that you need to correct and proper wild card dns setting which need to update httpd.conf and add litle bit things in whm ) if they provide wild card dns setting you do not need to use htaccess just use this method in index.php help here

Setting up Wildcard DNS for Subdomains on Cpanel | Wired Studios

can you able to open http://test.domain.com your main page or apache success ?

$serverhost = explode('.',$_SERVER["HTTP_HOST"]);
$sub = $serverhost[0];
if ($sub = "www") {
$sub = "";
}

there are also thing you need to check every http request which will check user from mysql if user is valid and it it will send as you want or where you want else could send at main page or 404 not found as you wish

there is an error in php code above, it should be:

$serverhost = explode('.',$_SERVER["HTTP_HOST"]);
$sub = $serverhost[0];
if ($sub == "www") {
$sub = "";
}

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

WhiteWarrior Principal · 1,419 posts #8

php_flag register_globals on RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)..DOMAIN.com$ RewriteCond %{HTTP_HOST} ^([^.]+).DOMAIN.com$ RewriteRule .* http://DOMAIN.com/%1 [R,L]

Will work, thats if i understand what you're trying todo 🙂

morency Senior · 488 posts #9

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z-]+) index.php?$1 [QSA,L]

For index.php

$sub = preg_replace("#(.*?)YOURSITE\.com$#i",'$1',$_SERVER["HTTP_HOST"]);

if ($sub == "www." || $sub == "YOURSITE.") {
$sub = "";}
if($sub != "") {
$sub = preg_replace("/(^www\.)?(.*)?\.$/i", '$2', $sub);
}
if ($sub == "YOURSITE") {
$sub = "";
}
if($sub == "") {
exit;
//or error for no user
}
$user=$sub;

$folder = explode("&",$_SERVER['QUERY_STRING'],2);
$folder=$folder[1];

echo"User: $user  <br />
Folder: $folder <br />
";
////from here use you coding with those two variables

Unamos los corazones,hoy todos somos multicolores!

neostar Developer · 109 posts #10

dows any one have working demo of this trick?

neostar Developer · 109 posts #11

does vbseo uses mod rewrite, url rewrite? like one the coding-talk is useing?

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close