Rewrite my.domain.com/var to domain.com/index.php?var=var

New to mod_rewrite? This is a good place to start.

Rewrite my.domain.com/var to domain.com/index.php?var=var

Postby rightnow » Sun Oct 07, 2007 11:16 am

Hello,

I've tried about 30 rewrites now and i cant get it to work..

I have a subdomain called "my" which is a folder on www.domain.com/my

Can someone help me with a rewrite that rewrites
my.domain.com/FOLDER to www.domain.com/index.php?var=FOLDER

All the rewrites ive tried cant break out of my my-directory.
I also want the URL to be hidden. No redirect.

Thanks guys and girls!

// Chris
rightnow
 
Posts: 1
Joined: Sun Oct 07, 2007 11:10 am

Postby richardk » Sun Oct 07, 2007 1:43 pm

All the rewrites ive tried cant break out of my my-directory.

You can't, you are limited to the sub domain's document root. Instead you need to create a file in /my called rewrite.php (you could call it anything) and put the following in it
Code: Select all
<?php require('../index.php');

Then in a .htaccess file in /my
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /rewrite.php?var=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 27 guests

cron