Forum Moderators: phranque

Message Too Old, No Replies

Looking for super-simple solution

         

ennovative

4:29 pm on Sep 4, 2014 (gmt 0)

10+ Year Member



I'm looking for the absolute simplest way of permanently redirecting this url:
http://www.example.com/component/sobipro/?sid=1:business-directory&Itemid=0
to this other URL:
http://www.example.com/directory by using .htaccess

I've spent 4 hours reading through documentation, but it almost all seems more complex than it needs to be.

Using Apache 2.2.27

[edited by: Ocean10000 at 6:25 pm (utc) on Sep 4, 2014]
[edit reason] Examplified. [/edit]

wilderness

10:45 pm on Sep 4, 2014 (gmt 0)

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



Forum search ?sid=1 [google.com]

look at the results in /apache forum

ennovative

11:07 pm on Sep 4, 2014 (gmt 0)

10+ Year Member



After sifting through yet more stuff that was overkill, I've finally found the simple solution. For anyone looking for the answer, here are the two lines to add (assuming you already have rewrite engine turned on):

RewriteCond %{QUERY_STRING} &?sid=1:business-directory&Itemid=0$
RewriteRule ^index\.php$ http://www.example.com/directory/? [R=301,L]

phranque

11:18 pm on Sep 4, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, ennovative!

redirecting this url:
http://www.example.com/component/sobipro/?sid=1:business-directory&Itemid=0

RewriteRule ^index\.php$ http://www.example.com/directory/? [R=301,L]

it doesn't look like the pattern for the RewriteRule will match the request.

lucy24

7:11 am on Sep 5, 2014 (gmt 0)

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



In addition to what phranque said about "index.php" (which may just be an artifact of cutting-and-pasting)...

What is the point of
&?

in the pattern of the RewriteCond? The two characters together just mean "optional ampersand" -- and since the pattern has no opening anchor, you can just leave off the & altogether.

Do the query elements
sid=blahblah
and
Itemid=blahblah
always come in that order, with nothing in between? It may be safer to split the two items as
RewriteCond %{QUERY_STRING} (&|^)sid=1:business-directory(&|$)
RewriteCond %{QUERY_STRING} (&|^)Itemid=0(&|$)

so they can come in either order.

When looking at query strings in a RewriteCond, your anchors should take the special forms
(&|^)
and
(&|$)
Together they delimit a single parameter, and mean "This is either the first parameter, or there's a & joining it to other parameters" and similarly "This is either the last parameter or" etcetera. The only exception is when there must not be any other parameters; then you use the ordinary ^ and $ anchors.

:: noting irritably that I passed a nice round number when I wasn't even paying attention ::

not2easy

2:54 pm on Sep 5, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Congrats on 10K Lucy! If you wrote more fluff it might have been noticed, just sayin' :)

ennovative

3:06 pm on Sep 5, 2014 (gmt 0)

10+ Year Member



@phranque & lucy24 - no idea. I was just looking for a straightforward answer, found one that works for me and I'm never touching it again.

Thanks for taking the time either way :)