Forum Moderators: phranque
I've had partial success by inserting into .htaccess the following:
RewriteRule ^index.php$ index.php?option=com_content&task=blogcategory&id=1&Itemid=2 [NC,L] but any address with index.php in it will redirect. For example, [mydomain.com...]
will redirect. I want ONLY [mydomain.com...] to redirect. (Actually I want [mydomain.com...] to redirect, too.)
Any suggestions about how to write the rule to apply to index.php specifically (without any trailing characters)?
(BTW, I'm not using Redirect 301 because it doesn't seem to like URL's with IP addresses in them)
Thanks,
Jim
You don't specify a "file name" to be redirected from, you specify a URL-path. As mod_rewrite makes clear, filenames are associated with URLs, but the two are not the same thing at all.
Then we have URLs: In "http://www.example.com/index.php?option=com_content&task=blogcategory&id=1&Itemid=2" the URL is "http://www.example.com/index.php" only -- The rest of it is the query string attached to, but not part of, the URL.
Finally, mod_rewrite can do two main things: It can externally redirect a requested URL-path to another URL, or in can internally rewrite a requested URL-path to a different filepath than that URL-path would be associated with by default. In an external redirect, the client (e.g. browser or robot) is told to re-request the resource it just requested, but from a new and different URL. In an internal rewrite, the requested resource is simply served from a new filepath.
Now with all of that out of the way, the solution may be clearer:
# If query string is blank
RewriteCond %{QUERY_STRING} ^$
# rewrite index.php request to add query string
RewriteRule ^index\.php$ /index.php?option=com_content&task=blogcategory&id=1&Itemid=2 [L]
I really cannot recommend that you have a redirect to another URL sitting at the root of your site.
I would do the redirect the other way around, so that it is "/" that gets indexed be search engines.