Forum Moderators: phranque
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!
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]
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