Forum Moderators: phranque

Message Too Old, No Replies

rewrite abc.domain.com to domain.com/search.php?q=abc

virtual subdomain abc.domain.com = domain.com/search.php=?abc

         

bluetoothache

10:23 am on Jan 25, 2007 (gmt 0)

10+ Year Member



Hi,

i would really appreciate it if anyone cound help me with this mod rewrite.

I need to rewrite

example.com/search.php?q=yyyy:#*$!x:

to

#*$!x.example.com

or

#*$!x-yyyy.example.com if the above example is not possible given the yyyy variable.

I have this code

Quote:RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
Rewriterule ^$ /search.php?q=category:%2: [L]
Rewriterule ^$ /search.php?q=brand:%2: [L]
Rewriterule ^$ /search.php?q=merchant:%2: [L]
Rewriterule ^$ /search.php?q=%2 [L]

It works only on category (first line)

How can i modify the code to work with the brand and merchant subdomains conditions?

I am also getting
an error on browsing the main domain

example.com
and
www.example.com

it shows the results of page

http://example.com/search.php?q=category::

thank you in advance!

bluetoothache

10:25 am on Jan 25, 2007 (gmt 0)

10+ Year Member



note:

all the #*$! characters above corresponts to a variable..

its ( ex ex ex ) 3x which was auto converted by forum app.

thanks.

jdMorgan

4:01 pm on Jan 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It appears from your code that you are misunderstanding the process, and perhaps even the purpose of mod_rewrite.

Your code is trying to rewrite the same requested URL to several different server filepaths, so only the first rule will work.

Have a look through our Apache forum library [webmasterworld.com], and particularly this thread [webmasterworld.com]. That should get you headed in the right direction and help you to define your requirements better.

[added] On review, the specific problem may be this: RewriteConds apply *only* to the single RewriteRule which follows; Therefore, only your first rule will be conditional and only your first rule will be able to access the %2 variable defined in the RewriteCond. [/added]

Jim

[edited by: jdMorgan at 4:05 pm (utc) on Jan. 25, 2007]

jdMorgan

4:25 pm on Jan 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another point is that using the www-category-product-example.com URL-plan is likely to get you in trouble for having far too many subdomains -- I cannot recommend that approach.

I'd suggest re-architecting your URL plan to "acknowledge" the search function in the URL itself. Something like:

www.example.com/brand/brandname --> search.php?brand=brandname
www.example.com/category/category --> search.php?category=categoryname
www.example.com/merchant/merchantname --> search.php?merchant=merchantname

If the URL-space is tightly-scoped to brand, category, and merchant, then you could shorten the published URLs to

www.example.com/b/brandname --> search.php?brand=brandname
www.example.com/c/categoryname --> search.php?category=categoryname
www.example.com/m/merchantname --> search.php?merchant=merchantname

However, if you plan to expand the search-type URL-space to handle many more search functions, then the explicit approach is better because it won't result in URL "collisions" as you add more search types.

The only use of a subdomain to separate this search function from your regular URL-space that I would feel even moderately comfortable with search-engine-ranking-wise is to use a single separate subdomain of "search.example.com".

Jim

bluetoothache

4:18 am on Jan 27, 2007 (gmt 0)

10+ Year Member



jdMorgan,

ok thanks for the comments and tips.