Forum Moderators: phranque

Message Too Old, No Replies

How to rewrite subdomain to file

rewrite subdomain

         

colombo

8:49 am on Apr 7, 2007 (gmt 0)

10+ Year Member



Hello,

Here what i want to rewrite:

sub.example.com/variable

TO

www.example.com/file-name.php?a=variable

the subdomain is existing, its a vitual sub domain.

pls help me.

thanks, Oren.

[edited by: jdMorgan at 3:40 pm (utc) on April 7, 2007]
[edit reason] example.com [/edit]

g1smd

11:58 pm on Apr 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you tried already?

Do you need a 301 redirect (where the URL in the browser changes to be the new one) or an internal rewrite (where the URL in the browser continues to show the requested URL)?

colombo

5:02 am on Apr 8, 2007 (gmt 0)

10+ Year Member



Hi,
thanks for the help.

so i don't wont 301 redirect and i want the url not to change.

here is my code ( i put it in the .htaccess under the subdomain):

rewriteengine on
rewritebase /

rewriterule (.*)$ http://www.example.biz/new_online_games.php?current=$1 [NC,l]

the problem is that the url is changing

<snip>

thanks

[edited by: jdMorgan at 1:26 pm (utc) on April 8, 2007]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

2:07 pm on Apr 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you include the protocol and domain in the substitution URL, then an external redirect will be generated, changing the client browser's address bar. This behaviour is documented in the mod_rewrite documentation.

For an internal rewrite, you need something like:


RewriteEngine on
RewriteBase /
#
RewriteCond $1 !^new_online_games\.php$
RewriteRule (.*) /new_online_games.php?current=$1 [L]

The RewriteCond is intended to prevent a rewriting loop, since otherwise *all* URLs will be rewritten to the php file, including the php file itself.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

colombo

6:01 am on Apr 9, 2007 (gmt 0)

10+ Year Member



Thank you very much it works :)