Creating subdomain using mod rewrite, possible?

Using a single web hosting account to host multiple sites

Creating subdomain using mod rewrite, possible?

Postby sowers » Sun Jan 25, 2009 6:33 pm

hello,

Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com

on their browser's address bar, it will get / retrieve the contents of the page from

Blog URL: http://www.yourdomain.com/blog.php?user=username

(but the address bar will remain as is Blog URL: http://username.yourdomain.com


Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com/id1/

on their browser's address bar, it will get / retrieve the contents of the page from

Blog Entry URL: http://www.yourdomain.com/blog.php?user=username&blogentry_id=id1

(but the address bar will remain as is Blog URL: http://username.yourdomain.com/id1/


Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com/trackback/id1/

on their browser's address bar, it will get / retrieve the contents of the page from

Blog Trackback URL: http://www.yourdomain.com/blog_ajax.php?
task=trackback&user=username&blogentry_id=id1



(but the address bar will remain as is Blog URL: http://username.yourdomain.com/trackback/id1/



I am grateful for the help

:D
sowers
 
Posts: 3
Joined: Sun Jan 18, 2009 6:50 pm

Postby richardk » Sun Feb 01, 2009 6:12 am

You have to create DNS for the sub domains.
Your server has to be configured to send all the sub domain requests to the same directory (with the .htaccess and PHP files in it).

Then you can try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule .* - [E:BLOG_USERNAME=%1]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^$ /blog.php?user=%1 [QSA,L]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^([0-9]+)/?$ /blog.php?user=%1&blogentry_id=$1 [QSA,L]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^trackback/([0-9]+)/?$ //blog_ajax.php?
task=trackback&user=%1&blogentry_id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sowers » Sun Feb 01, 2009 10:03 am

Hi richardk,

My Normal URLs:

Code: Select all
Profile URL: http://www.yourdomain.com/profile.php?user=username
Album List URL: http://www.yourdomain.com/albums.php?user=username
Album URL: http://www.yourdomain.com/album.php?user=username&album_id=id1
Photo URL: http://www.yourdomain.com/album_file.php?user=username&album_id=id1&media_id=id2

Blog URL: http://www.yourdomain.com/blog.php?user=username
Blog Entry URL: http://www.yourdomain.com/blog.php?user=username&blogentry_id=id1
Blog Trackback URL: http://www.yourdomain.com/blog_ajax.php?
task=trackback&user=username&blogentry_id=id1

Event URL: http://www.yourdomain.com/event.php?event_id=id1
Event Media URL: http://www.yourdomain.com/event_album_file.php?event_id=id1&eventmedia_id=id2
Classifieds URL: http://www.yourdomain.com/classifieds.php?user=username
Classified Listing URL: http://www.yourdomain.com/classified.php?user=username&classified_id=id1
Polls URL: http://www.yourdomain.com/polls.php?user=username
Poll URL: http://www.yourdomain.com/poll.php?user=username&poll_id=id1



This user .htaccess below:

Code: Select all
RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/images/(.*)$ /images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/uploads_user/(.*)$ /uploads_user/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /profile.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)?$ /profile.php?user=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/([^/]*)$ /group.php?group_id=$1$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/album/([0-9]+)/([^/]*)$ /group_album_file.php?group_id=$2&groupmedia_id=$3$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3&grouppost_id=$4$5 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/polls/([0-9]+)/?$ /poll.php?user=$1&poll_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/polls/([0-9]+)/([^/]+)?$ /poll.php?user=$1&poll_id=$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/polls/?$ /polls.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/([0-9]+)/?$ /classified.php?user=$1&classified_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/([0-9]+)/([^/]+)?$ /classified.php?user=$1&classified_id=$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/?$ /classifieds.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?event/([0-9]+)/([^/]*)$ /event.php?event_id=$1$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?event/([0-9]+)/album/([0-9]+)/([^/]*)$ /event_album_file.php?event_id=$2&eventmedia_id=$3$4 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/([0-9]+)/?$ /blog.php?user=$1&blogentry_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/([^/]+)?$ /blog.php?user=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/?$ /blog.php?user=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/trackback/([0-9]+)/?$ /blog_ajax.php?task=trackback&user=$1&blogentry_id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/albums/([0-9]+)/([0-9]+)/?$ /album_file.php?user=$1&album_id=$2&media_id=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/albums/([0-9]+)/?$ /album.php?user=$1&album_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/albums/([0-9]+)/([^/]+)?$ /album.php?user=$1&album_id=$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/albums/?$ /albums.php?user=$1 [L]


and address of the website is thus:

Subdirectory URLs
Code: Select all
Profile URL: http://www.yourdomain.com/username
Album List URL: http://www.yourdomain.com/username/albums/
Album URL: http://www.yourdomain.com/username/albums/id1
Photo URL: http://www.yourdomain.com/username/albums/id1/id2
[b]Blog URL: http://www.yourdomain.com/username/blog/
Blog Entry URL: http://www.yourdomain.com/username/blog/id1/
Blog Trackback URL: http://www.yourdomain.com/username/trackback/id1/[/b]
Event URL: http://www.yourdomain.com/event/id1/
Event Media URL: http://www.yourdomain.com/event/id1/album/id2/
Classifieds URL: http://www.yourdomain.com/username/classifieds/
Classified Listing URL: http://www.yourdomain.com/username/classifieds/id1/
Polls URL: http://www.yourdomain.com/username/polls/
Poll URL: http://www.yourdomain.com/username/polls/id1/


Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com

on their browser's address bar, it will get / retrieve the contents of the page from

Blog URL: http://www.yourdomain.com/blog.php?user=username

(but the address bar will remain as is Blog URL: http://username.yourdomain.com


Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com/id1/

on their browser's address bar, it will get / retrieve the contents of the page from

Blog Entry URL: http://www.yourdomain.com/blog.php?user=username&blogentry_id=id1

(but the address bar will remain as is Blog URL: http://username.yourdomain.com/id1/


Is it possible that when a visitor typed in

Blog URL: http://username.yourdomain.com/trackback/id1/

on their browser's address bar, it will get / retrieve the contents of the page from

Blog Trackback URL: http://www.yourdomain.com/blog_ajax.php?
task=trackback&user=username&blogentry_id=id1



(but the address bar will remain as is Blog URL: http://username.yourdomain.com/trackback/id1/




using wildcard dns and the same effect of wordpress multi user:

I am grateful for the help
sowers
 
Posts: 3
Joined: Sun Jan 18, 2009 6:50 pm

Postby richardk » Sun Feb 01, 2009 11:48 am

Do you have DNS for the sub domains?
What happens when you visit the sub domains? (What directory or file do you see?)

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L,QSA]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.+/(images|uploads_user)(/(.*))?$ /$1/$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)(?:/([^/]+))??$ /profile.php?user=$1$2 [L]

RewriteRule ^group/([0-9]+)/([^/]*)$                              /group.php?group_id=$1$2 [L]
RewriteRule ^group/([0-9]+)/album/([0-9]+)/([^/]*)$               /group_album_file.php?group_id=$1&groupmedia_id=$2$3 [L]
RewriteRule ^group/([0-9]+)/discussion/([0-9]+)/([^/]*)$          /group_discussion_view.php?group_id=$1&grouptopic_id=$2$3 [L]
RewriteRule ^group/([0-9]+)/discussion/([0-9]+)/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$1&grouptopic_id=$2&grouppost_id=$3$4 [L]


RewriteRule ^([^/]+)/polls/([0-9]+)/?$       /poll.php?user=$1&poll_id=$2   [L]
RewriteRule ^([^/]+)/polls/([0-9]+)/([^/]*)$ /poll.php?user=$1&poll_id=$2$3 [L]
RewriteRule ^([^/]+)/polls/?$                /polls.php?user=$1             [L]

RewriteRule ^([^/]+)/classifieds/([0-9]+)/?$       /classified.php?user=$1&classified_id=$2   [L]
RewriteRule ^([^/]+)/classifieds/([0-9]+)/([^/]*)$ /classified.php?user=$1&classified_id=$2$3 [L]
RewriteRule ^([^/]+)/classifieds/?$                /classifieds.php?user=$1                   [L]

RewriteRule ^event/([0-9]+)/([^/]*)$                /event.php?event_id=$1$2                             [L]
RewriteRule ^event/([0-9]+)/album/([0-9]+)/([^/]*)$ /event_album_file.php?event_id=$1&eventmedia_id=$2$3 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule .* - [E:BLOG_USERNAME=%1]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^$ /blog.php?user=%1 [QSA,L]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^([0-9]+)/?$ /blog.php?user=%1&blogentry_id=$1 [QSA,L]

RewriteCond %{ENV:BLOG_USERNAME} ^(.+)$
RewriteRule ^trackback/([0-9]+)/?$ //blog_ajax.php?task=trackback&user=%1&blogentry_id=$1 [QSA,L]

RewriteRule ^([^/]+)/albums/([0-9]+)/([0-9]+)/?$ /album_file.php?user=$1&album_id=$2&media_id=$3 [L]
RewriteRule ^([^/]+)/albums/([0-9]+)/?$          /album.php?user=$1&album_id=$2                  [L]
RewriteRule ^([^/]+)/albums/([0-9]+)/([^/]+)?$   /album.php?user=$1&album_id=$2$3                [L]
RewriteRule ^([^/]+)/albums/?$                   /albums.php?user=$1                             [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sowers » Sun Feb 01, 2009 6:06 pm

Hello richardk,

1- i have DNS for the sub domains.

2- Copy this code pro file. Htaccess for my site and this error occurred:

500 - Internal Server Error
sowers
 
Posts: 3
Joined: Sun Jan 18, 2009 6:50 pm

Postby richardk » Mon Feb 02, 2009 4:54 am

What happens when you visit the sub domains? (What directory or file do you see?)



2- Copy this code pro file. Htaccess for my site and this error occurred:

500 - Internal Server Error

Code: Select all
[E:BLOG_USERNAME=%1]

should be
Code: Select all
[E=BLOG_USERNAME:%1]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 32 guests

cron