Problems with subdomain.domain.com

Oh, the strange things mod_rewrite does!

Problems with subdomain.domain.com

Postby rynox » Thu Jul 03, 2008 11:06 pm

Well i'm experimenting with mod rewrite.
I managed to get some subdomains working, but the outcome aint perfect yet. 'www', 'forum', 'img' and 'my' all work perfectly as subdomains.
Here is my code:

Code: Select all
Options +indexes
Options +FollowSymLinks

RewriteEngine On

#loop stopping code.
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

#display news /news/id/
RewriteRule ^news/([0-9]+)/$ /news/viewnews.php?id=$1 [NC,L]

#display an error /error/errortag/
RewriteRule ^error/([a-z]+)/$ /errors/displayError.php?error=$1 [NC,L]

#logout by visiting this link /logout/
RewriteRule ^logout/$ /logout.php [NC,L]

#forward to root
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ /$1 [QSA,L]

#forward to root
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ /$1 [QSA,L]

#forward to forums
RewriteCond %{HTTP_HOST} ^forum\.example\.com$ [NC]
RewriteRule ^(.*)$ /forum/$1 [QSA,L]

#forward to images
RewriteCond %{HTTP_HOST} ^img\.example\.com$ [NC]
RewriteRule ^(.*)$ /images/$1 [QSA,L]

#forward to account
RewriteCond %{HTTP_HOST} ^my\.example\.com$ [NC]
RewriteRule ^(.*)$ /account/$1 [QSA,L]

#forward to users
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
RewriteRule ^users/($1)/ [L]

#404 error handling
ErrorDocument 404 /errors/index.php


Could anyone help me make this work?
For some reason the 404 errorhandling doens't work either.
rynox
 
Posts: 4
Joined: Thu Jul 03, 2008 10:54 pm

Postby richardk » Fri Jul 04, 2008 3:09 pm

This part? It isn't a valid RewriteRule.
Code: Select all
#forward to users
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
RewriteRule ^users/($1)/ [L]

Where is it supposed to rewrite to?

For abc.example.com/def to /users/abc/def, try
Code: Select all
Options +FollowSymLinks +Indexes
ErrorDocument 404 /errors/index.php

RewriteEngine On

# Loop stopping code.
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule ^ - [L]

# Display news /news/id/
RewriteRule ^news/([0-9]+)/$ /news/viewnews.php?id=$1 [NC,L]

# Display an error /error/errortag/
RewriteRule ^error/([a-z]+)/$ /errors/displayError.php?error=$1 [NC,L]

# Logout by visiting this link /logout/
RewriteRule ^logout/$ /logout.php [NC,L]

# Forward to forums
RewriteCond %{HTTP_HOST} ^forum\.example\.com$ [NC]
RewriteRule ^(.*)$ /forum/$1 [QSA,L]

# Forward to images
RewriteCond %{HTTP_HOST} ^img\.example\.com$ [NC]
RewriteRule ^(.*)$ /images/$1 [QSA,L]

# Forward to account
RewriteCond %{HTTP_HOST} ^my\.example\.com$ [NC]
RewriteRule ^(.*)$ /account/$1 [QSA,L]

# Forward to users
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /users/%1/$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 13 guests

cron