Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite subdomain to a script...

         

compbum

1:04 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Hey all...
Nice forums here...

Currently I have this...

RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) [mydomain.com...] [R]

Which takes [mydomain.com...] and redirects it to [mydomain.com...]

However I am looking for some code to do this...

[whatever.mydomain.com...] and redirects it to [mydomain.com...]

I hope this makes sense.. thank you in advance

compbum

2:02 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Got it working... found some code from another thread and modified.

RewriteCond %{REQUEST_URI}!^/index\.php
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com
RewriteRule ^(.*) [mydomain.com...] [L]

RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) [mydomain.com...] [R]

jdMorgan

3:29 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



compbum,

Welcome to WebmasterWorld!

The URL-path in the first line must match the name of the target script in the RewriteRule. The function of the first line is to prevent rewrite looping.

In order to avoid revealing your script's function, I'd also recommend using an internal rewrite, rather than a redirect (this could be a security issue). The RewriteRule changes as shown:


RewriteCond %{REQUEST_URI} !^/[b]script[/b]\.php
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com
RewriteRule (.*) [b]/script[/b].php?%1 [L]

Jim

compbum

4:24 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Well how can I hide what the script does but still pass through directives...

like.. script.php?sub&new=4

jdMorgan

10:44 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By using the code as shown above...

Jim

compbum

11:29 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Maybe I should be more clear...

Lets say someone wants to go to..

sub.mydomain.com/?new=4

I want sub.mydomain.com to redirect to script.php?sub

but sub.mydomain.com/?new=4 goes to script.php?sub&new=4

jdMorgan

2:15 am on Jun 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, you do or not not want to pass the users request for "new=4"?

If so, add QSA to the RewriteRule flags, making it "[QSA,L]"

Sorry to seem a bit dim here, but this stuff requires precision in the implementation, and that requires precision in the requirements specification.

Jim