Forum Moderators: phranque

Message Too Old, No Replies

Wildcard subdomain to directory

         

ralphje

6:45 pm on Nov 12, 2007 (gmt 0)

10+ Year Member



Heey,

Well I've searched your topics for the appropriate information and I've found some information, namely in the topic at this topic [webmasterworld.com].

However, for some reason I get an 500-error when I enter a subdomain. This is my current .htaccess, with some rules left out because it's a huge file.

Can someone please help me out?


# Errorpagina
ErrorDocument 401 etc. etc.

# PHP Variabelen
php_value etc. etc.

# S2M3
RewriteRule ^m$ http://www.example.com/v3/m [L,NC]
RewriteRule ^m/(.*)$ http://www.example.com/v3/m/$1 [L,NC]

##############################################################################################

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

# Voorkom bekijken htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>

#voorkom example.com
rewritecond %{http_host} ^example\.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.nl(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]

##############################################################################################

# Aliasses
## Weblogs
RewriteRule ^blog/(.+)/?$ http://www.example.com/weblog/$1 [L,NC]

[about 100 lines]

# Paginas als www.ralphje.nl/hoi -> www.ralphje.nl/hoi.php als map hoi niet bestaat én bestand hoi niet bestaat
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ $1.php?action=$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php

###
# Catching everything uncatched
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^([A-Za-z0-9-]+)/?$ http://www.example.com/weblog/$1 [L,NC]

# Dit is bovendien de fix voor de paginanummering
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^([A-Za-z0-9-]+)/(.+)/?$ http://www.example.com/weblog/$1/$2 [L,NC]

[edited by: jdMorgan at 12:09 am (utc) on Nov. 13, 2007]
[edit reason] Example.com. Please see Terms of Service. [/edit]

ralphje

12:10 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



Can you please help me? I'm quite desperate.

jdMorgan

4:56 pm on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is simply too much code to ask the members here to debug. If you can narrow down the problem to the specific section of code that is causing the error, you'll likely get a better response. You can do this by commenting-out one section at a time and re-testing after completely flushing your browser cache. Or perhaps you know which section you added which caused the 500-server error.

Also, please confirm that your operating system supports POSIX 1003.2 regular expressions -- This is required in order to use the back-reference method shown here. (Also note that because of this, the code has limited portability across server operating systms, which may be a concern if you need to change hosting platforms in the future).

Jim

ralphje

7:12 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



I think that's the problem, since the problem occurred only since adding the part of that topic, since my error is still 'too much redirects'. Is there any other way to let the subdomain refer to that folder?

jdMorgan

8:02 pm on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are several ways. Do you have any objection to storing the subdomain files at a path like "example.com/subs/<subdomain-name>" instead of storing them at "example.com/<subdomain-name>"?

Jim

ralphje

12:57 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



Well in fact, they should be rewritten from, let's say user.example.com to www.example.com/weblog/user, so I say 'yes'.

jdMorgan

3:06 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Rewrite <subdomain>.example.com/<path> to example.com/weblog/<subdomain>/<path>
#
# Rewrite only if not already rewritten to /weblog/
RewriteCond $1 !weblog/
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.nl(:80)?$
# Rewrite to /weblog/subdomain/URL-path
RewriteRule (.*) /weblog/%1/$1 [L]

Jim