www.domain.com/directory => directory.domain.com

Using a single web hosting account to host multiple sites

www.domain.com/directory => directory.domain.com

Postby justanothernoob » Mon Feb 12, 2007 9:17 am

Hi, I'm a total mod_rewrite noob, but I need help. I'm currently using a CMS, which turns queries into virtual directories like this:

Code: Select all
<IfModule mod_php4.c>
    php_value session.use_trans_sid 0
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&commentspage=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/ index.php?category=$1&nbsp;articlespage=$2 [L]


Baiscally, index.php?category=$1&title=$2&commentspage=$3

is translated into: /category/title/commentspage/

My server is already setup to recognize the subdomains. But currently the above .htaccess code won't allow it. Is there someway that it can be modified to display the same dynamically displayed content as both:

www.domain.com/category/ and category.domain.com?

Any articles under the category would be:

category.domain.com/article/
or
category.domain.com/title/
or
category.domain.com/title/commentspage/

Also, if it could be told to exclude making the 'home' category a subdomain, that would be awesome.
justanothernoob
 
Posts: 8
Joined: Mon Feb 12, 2007 9:11 am

Postby richardk » Tue Feb 13, 2007 11:25 am

Try:
Code: Select all
<IfModule mod_php4.c>
    php_value session.use_trans_sid 0
</IfModule>

Options +FollowSymLinks

RewriteEngine On

Rewritecond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule .* - [E:MCAT=%2]

RewriteCond %{ENV:MCAT} ^(.+)$
RewriteRule ^$ index.php?category=%1 [L]

RewriteCond %{ENV:MCAT} ^(.+)$
RewriteRule ^([0-9]+)/?$ index.php?category=%1&articlespage=$1 [L]

RewriteCond %{ENV:MCAT} ^(.+)$
RewriteRule ^([^/]+)/?$ index.php?category=%1&title=$1 [L]

RewriteCond %{ENV:MCAT} ^(.+)$
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?category=%1&title=$1&commentspage=$2 [L]

RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule .* - [L]

RewriteRule ^(.*)$ index.php?category=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/?$ index.php?category=$1&title=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/?$ index.php?category=$1&title=$2&commentspage=$3 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/?$ index.php?category=$1&articlespage=$2 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby justanothernoob » Wed Feb 14, 2007 9:12 am

:o Wow. Unfortunately it doesn't work. It throws a "internal error" message.
justanothernoob
 
Posts: 8
Joined: Mon Feb 12, 2007 9:11 am

Postby richardk » Wed Feb 14, 2007 11:12 am

What does you error log say? If you don't have access, ask your host.

But try this first:
Code: Select all
<IfModule mod_php4.c>
    php_value session.use_trans_sid 0
</IfModule>

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ index.php?category=%2 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([0-9]+)/?$ index.php?category=%2&articlespage=$1 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?category=%2&title=$1 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?category=%2&title=$1&commentspage=$2 [L]

RewriteCond %{ENV:REDIRECT_STATUS} !^$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/?$ index.php?category=$1&articlespage=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/?$ index.php?category=$1&title=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/?$ index.php?category=$1&title=$2&commentspage=$3 [L]

RewriteRule ^(.*)$ index.php?category=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby justanothernoob » Wed Feb 14, 2007 2:54 pm

:wink: Getting warmer. Now this works, again:

http://www.domain.com/category/

but this still does not. It merely displays the homepage...

http://category.domain.com/

Should I change !^www\.domain\.com$ [NC] to my actual domain name?

Uh, it also looks like if I click on a link to:
www.domain.com/category/article/

it merely stays on:
www.domain.com/category/

The error log had nothing related to .htaccess in there. All just old PHP warnings.
justanothernoob
 
Posts: 8
Joined: Mon Feb 12, 2007 9:11 am

Postby richardk » Fri Feb 16, 2007 7:52 am

You should change all "domain\.com"s to your domain (no www), make sure you escape the "." with a "\". Then try it.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby richardk » Fri Feb 16, 2007 4:37 pm

Do not PM me, you have a thread right here.

Hi, OK, now I'm using this:

Code:

<IfModule mod_php4.c>
php_value session.use_trans_sid 0
</IfModule>

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ index.php?category=%2 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([0-9]+)/?$ index.php?category=%2&articlespage=$1 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?category=%2&title=$1 [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?category=%2&title=$1&commentspage=$2 [L]

RewriteCond %{ENV:REDIRECT_STATUS} !^$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/?$ index.php?category=$1&articlespage=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/?$ index.php?category=$1&title=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/?$ index.php?category=$1&title=$2&commentspage=$3 [L]

RewriteRule ^(.*)$ index.php?category=$1 [L]


And the main categories are working fine.

http://www.domain.com/home/
http://www.domain.com/contact/
http://www.domain.com/alabama/
And even http://alabama.domain.com/

However, if I try to get to a individual article page (&title=$1), It doesn't redirect. It stays on the main category page. Any ideas?

http://www.domain.com/alabama/alabama-public-records/
http://www.domain.com/california/califo ... c-records/

I really appreciate your help btw. If this works, it may even help the entire sNews community too.


Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$ [OR]
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ index.php?category=%2 [L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([0-9]+)/?$ index.php?category=%2&articlespage=$1 [L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?category=%2&title=$1 [L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?category=%2&title=$1&commentspage=$2 [L]

RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?category=$1&articlespage=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?category=$1&title=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?category=$1&title=$2&commentspage=$3 [L]
RewriteRule ^(.+)$ index.php?category=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby justanothernoob » Fri Feb 16, 2007 4:54 pm

Thanks for not posting the URL.

That has pretty much the same result, except now http://alabama.domain.com/ isn't working. :(
justanothernoob
 
Posts: 8
Joined: Mon Feb 12, 2007 9:11 am

Postby richardk » Sat Feb 17, 2007 11:25 am

It works fine for me.

What do you see when you add the following to the top of index.php:
Code: Select all
<?php

header('Content-Type: text/plain', true, 200);
print_r($_GET);
exit();

?>

Are the variables correct?

Also, what do you mean by isn't working? A 404 page? The wrong page? (Which one?)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby justanothernoob » Sun Feb 18, 2007 1:22 pm

I won't be able to try your code out until monday, but try browsing the site again. And clear your cache.

Notice that even if the URL seems to change, the content of the page remains the same. :-? Something must be wrong with the query... sNews knows what artlcle/page to display based upon the query URL, and .htaccess is supposed to then change the URL to be SE friendly.
justanothernoob
 
Posts: 8
Joined: Mon Feb 12, 2007 9:11 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 24 guests

cron