Subdomain to url by Mod Rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Subdomain to url by Mod Rewrite

Postby mariatmind » Sat Nov 01, 2008 10:17 am

Hio, this is my problema,

I need to redirect

test.domain.com
to
www.domain.com/test.php?azione=$1&variabile=$1

by mod rewrite

Can you help me?

Thanks for all
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Postby richardk » Sat Nov 01, 2008 3:26 pm

Does test change?
Should $1 be replaced with something?

Try the following in test.example.com's document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?test\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/test.php?azione=$1&variabile=$1 [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mariatmind » Sat Nov 01, 2008 5:15 pm

Thanks for help,

it works, but when i digit

test.domain.com

it change to

www.domain.com/test.php?azione=$1&variabile=$1

i'd like that the url remain "test.domain.com" and it shows the page "www.domain.com/test.php?azione=$1&variabile=$1"

Excuse me for my english i'm italian
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Postby richardk » Sun Nov 02, 2008 2:12 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?test\.example\.com$ [NC]
RewriteRule ^(.*)$ /test.php?azione=$1&variabile=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mariatmind » Sun Nov 02, 2008 2:36 pm

Thanks again,

but it dosn't work,

I try to explain better what i need

I need to create e subdomain whit mod rewrite

i want create the subdomain

test.domain.com

that show te content of

www.domain.com/test.php?azione=$1&variabile=$1
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Postby richardk » Sun Nov 02, 2008 2:50 pm

What happens when you go to test.example.com with the last mod_rewrite?

Where are the test.php and .htaccess files?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mariatmind » Mon Nov 03, 2008 5:36 am

test.php and .htaccess are in folder:

/var/www/vhosts/example.com/httpdocs

when i use the last code you suggest it give me

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Postby mariatmind » Mon Nov 03, 2008 5:42 am

You are so polite,
i try to give you te precise situation:

i have the site:

www.example.com

and the file

www.example.com/test.php

I'd like that

Whed i poit to subdomain:

test.example.com

it shows me the content of

www.example.com/test.php

and for example when i point to:

test.example.com/category/([^/.]+)/

it shows me the content of

www.example.com/test.php?action=viewcat ... ategory=$1

if you can help me....

Thank .....
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Postby richardk » Mon Nov 03, 2008 12:11 pm

test.php and .htaccess are in folder:

/var/www/vhosts/example.com/httpdocs

What is test.example.com's document root? (With no mod_rewrite, what page do you see when you go to test.example.com?)

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?test\.example\.com$ [NC]
RewriteRule ^$ /test.php [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?test\.example\.com$ [NC]
RewriteRule ^(.+)$ /test.php?action=viewcategory&articlecategory=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mariatmind » Tue Nov 04, 2008 12:44 am

Now when i write

test.domain.com

it redirect to url

www.domain.com

What is test.example.com's document root? (With no mod_rewrite, what page do you see when you go to test.example.com?)


test.domain.com doesn't exist

I created WILDCARDS *.example.com and now each subdomain redirect to www.domain.com

i'd like that

([A-Za-z0-9_-]+).domain.com

shows

www.domain.com/userprofile.php?ID=$1

so each user has a subdomain for his profile

Thanks...
mariatmind
 
Posts: 6
Joined: Sat Nov 01, 2008 10:12 am

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 25 guests

cron