Forum Moderators: phranque

Message Too Old, No Replies

Correct syntax for RewriteRule?

How to specify the file name to be redirected from

         

jpschwartz

12:01 am on Mar 19, 2008 (gmt 0)

10+ Year Member



I'm trying to redirect
index.php to
index.php?option=com_content&task=blogcategory&id=1&Itemid=2

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

jdMorgan

2:30 am on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Part of the problem is that your confusing many of the 'pieces' here.

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]

Jim

g1smd

12:16 am on Mar 20, 2008 (gmt 0)

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



Oh dear. Looks like you're playing with Joomla; and that's one massive Duplicate Content nightmare.

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.

jpschwartz

3:14 pm on Mar 20, 2008 (gmt 0)

10+ Year Member



Thanks, guys. That's very helpful!

Jim