Forum Moderators: phranque

Message Too Old, No Replies

Sub domain internal redirecting

subdomain

         

jphilip

11:35 am on Jan 7, 2010 (gmt 0)

10+ Year Member



I have like 5 subdomains for my website "www.example.com" all pointing to the same folder public_html/

the 5 subdomains are ( all of them are categories)
electronics.example.com
sports.example.com
footwear.example.com
music.example.com
food.example.com

Then I want to do an internal rewrite using .htaccess( in public_html/) to the appropriate category link WITHOUT CHANGING THE URL

My htaccess code is something like this
===================================================

RewriteCond %{HTTP_HOST} ^(music\.)example.com
RewriteRule ^(.*)$ /index.php?option=com_cat&Itemid=229&cat_id=1234 [L]

===================================================
This gives me a 500 Internal Server Error
If I remove the rewrite rule and directly type the following in the url
[music.example.com...]
it works but I want the url only [music.example.com...]

if my code is modified as follows
===================================================

RewriteCond %{HTTP_HOST} ^(music\.)example.com
RewriteRule http://www.example.com/index.php?option=com_cat&Itemid=229&cat_id=1234 [L]

===================================================
it works but the url changes beacuse of the external redirect

Basically in short I want "http://music.example.com" to point to the music category link
"http://music.example.com/index.php?option=com_cat&Itemid=229&cat_id=1234"

My modrewrite knowledge is just 1 day old...reading the apache document is a pain for beginners like me...

Justin

[edited by: jdMorgan at 8:13 pm (utc) on Jan. 7, 2010]
[edit reason] example.com [/edit]

jdMorgan

8:09 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A look at your server error log file would likely have given you a strong hint that you've got an 'infinite' rewriting loop here. You need to explicitly prevent this looping whenever your code is in .htaccess and the rewrite's target path will match its pattern:

RewriteCond %{HTTP_HOST} ^music\.example\.com
RewriteRule !^index\.php$ /index.php?option=com_cat&Itemid=229&cat_id=1234 [L]

Note that I removed all parentheses because they were not used either to create back-references or to enclose optional or quantified sub-patterns.

Jim

jphilip

9:24 pm on Jan 7, 2010 (gmt 0)

10+ Year Member



Hi jim ,
thanks for the quick response..I apologize for creating a similar thread! I am under a huge pressure to solve this asap
Anyways I understand what u wanted me to do....I did try using negate(!) to stop an infinite loop ....But that was not the problem .... it had something to do with the forward slash.When I replaced "/index.php?option=.." with "index.php?option=" it did not show an internal error
But it now shows me a blank page....

This is my code
RewriteCond %{HTTP_HOST} ^music\.example\.com
RewriteRule ^.*$ index.php?option=com_dating&Itemid=456&cat_id=5370&lang=en&task=showtopDates [L]

But If I type any other character instead of " ^.*$ " in the regex pattern
eg. " RewriteRule ^xyz$ index.php?option ..... "
and then access the url with eg music.example.com/xyz it works fine ...

I have tried .* , ^.* , !\s* and many more but still get the same blank page...

[edited by: jdMorgan at 11:01 pm (utc) on Jan. 7, 2010]
[edit reason] example.com [/edit]

jdMorgan

10:39 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must exclude index.php as previously stated.

If you do not, the request will be rewritten to "index.php?option=com_dating&Itemid=456&cat_id=5370&lang=en&task=showtopDates [L]", mod_rewrite processing will restart, and the request will be rewritten again. Lather, rinse, repeat. This will continue until the server gives up and logs a "Maximum internal redirect limit exceeeded" error.

Note also that you are rewriting *all* URLs in the music.example.com domain to your script. That means that your script must provide all images, css, JavaScript code, etc. as well as robots.txt and sitemap.xml when requested, and it must do so based on that *same* script-path and query string in each case. It must also properly handle requests for known-not-to-exist test URLs used by Google and Yahoo Webmaster tools, etc., and return a proper 404-Not Found response. Be sure that's what you actually want to do.

Jim

g1smd

11:54 pm on Jan 7, 2010 (gmt 0)

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



..

jphilip

5:26 am on Jan 8, 2010 (gmt 0)

10+ Year Member



I did exclude the index.php as below
RewriteCond %{HTTP_HOST} ^skating\.example\.com
RewriteRule !^index\.php.*$ index.php?option=com_rating&Itemid=229&cat_id=4348&lang=en&task=showtopblog [L]
But that did not solve it either

If I remove all the parameters "option=com_rating..." It works ! ..So I guess it has something to do with the parameters ?

Also I do have javascript,css etc having relative paths...I'll make it absolute

" and it must do so based on that *same* script-path and query string in each case "
I didnt quite understand this...are you saying that my query string too is appended in all the request...will making all the links absolute solve this ?

[edited by: jdMorgan at 8:14 am (utc) on Jan. 8, 2010]
[edit reason] example.com [/edit]

jdMorgan

8:13 am on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I mean that with your code as shown above, every URL under skating.example.com leads to your script... Page URLs, image URLS, JS file URLs, robots.txt, everything. And the script will see only "option=com_rating&Itemid=229&cat_id=4348&lang=en&task=showtopblog" for each and every one of those requests.

Is that what you want?

If not, you will need a more-specific pattern in your rule.

Jim