htaccess help.

Reaction score
341
I need some help on making an htaccess file which does something like this;

www.sub.mysite.com/file.php

redirects to

www.mysite.com/file.php?var=sub

It needs to be dynamic so it works with any file in the directory and any subdomain.
It also needs to mask the domain, so in the header it would look like sub.mysite.com/file.php still.

Think of it in terms like this;

$1 = the file
$2 = subdomain

www.$2.mysite.com/$1

redirects to

www.mysite.com/$1?var=$2
 

UndeadDragon

Super Moderator
Reaction score
447
Maybe...:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.mysite.com/$1 [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1?var=$2 [L,R=301]

I am not sure if it will work, as htaccess is not really something I am strong with.
 
Reaction score
341
The above code appears to only work on the 'sub' subdomain (not tested).

I need it to work on any subdomain (it needs to be dynamic).
 

JerseyFoo

1/g = g-1
Reaction score
40
Googled "apache htaccess subdomains". First result appears to say that..
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ([^\.]*).domain.com$ 
RewriteRule (.*)$ /$1?var=%1 [L]
...should work.

It also needs to mask the domain, so in the header it would look like sub.mysite.com/file.php still.
It's called a rewrite, not redirect.
 
Reaction score
341
PHP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ([^\.]*).ezforums.net$ 
RewriteRule (.*)$ ezforums.net/phpbb/$1?access_name=%1 [L]

Gives a 500 internal server error.

PHP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ([^\.]*).ezforums.net$ 
RewriteRule (.*)$ ezforums.net/phpbb/index.php?access_name=%1 [L]

Works, but every link of course directs to index.php.

I checked what the value of $1 and it was indeed the filename. I have no idea whats wrong.
 

JerseyFoo

1/g = g-1
Reaction score
40
It's a parse error, I haven't used apache in a long time though.

Probably in this area
Code:
RewriteRule (.*)$ ezforums.net/p
 
Reaction score
341
$1 must be causing the parse error then because it works without it.

Even though it works if I use it as a PHP argument (?access_name=$1).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top