Forum Moderators: phranque

Message Too Old, No Replies

How to rewrite variables in .htaccess?

         

Mark33

10:11 pm on Mar 16, 2009 (gmt 0)

10+ Year Member



Hi,

Can somebody please help me to rewrite variables from:

mysite.com/index.php?option=com_sobi2&tag=someword
to
mysite.com/Search.html?searchword=someword

So this part from the middle "index.php?option=com_sobi2&tag="
should be replaced with this one "Search.html?searchword="

I'm a newbie so please be specific.I have some 1500 URLs to rewrite like this.
What exactly should I put in my htaccess file?I tryed something on my own,but it just doesn't work...

Thanks in advance.

g1smd

2:08 am on Mar 17, 2009 (gmt 0)

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



This is similar to many other questions in recent days. Check recent examples for many of the components you will need.

What have you tried already?

This forum can help you fix your code, but as most people here have jobs to be getting on with elsewhere, this isn't an unpaid code-writing service.

If it is to be a redirect you will need the full domain name in the target URL, and will end with [R=301,L]. You'll need a RewriteCond to look at QUERY_STRING too.

For a rewrite, omit the domain name and end the rule with [L].

Which URL are you linking to from your pages? Which URL should be be seeing and using to access the content? What is the local filepath inside the server for where the content really resides?

Normally I just beat my head on the wall when dealing with Joomla! sites. It has a very large bucketful of Dupe Content issues.

[edited by: g1smd at 2:27 am (utc) on Mar. 17, 2009]

Mark33

2:23 am on Mar 17, 2009 (gmt 0)

10+ Year Member



Sorry,but I'm a total newbie,and I was reading this forum but I couldnt get this to work.Anyway I tryed with this code,but got error code 500 from apache:

mod_rewrite in use

RewriteEngine On

RewriteRule ^(/?tag=)/?$ search.html?searchword=$1 [QSA,L]

There is one more thing.I need to replace & character with + in query string append in order to get this to work.

Again,I'm so sorry but I just can't get much better than that...

This is about Joomla site.

[edited by: Mark33 at 2:34 am (utc) on Mar. 17, 2009]

g1smd

8:49 pm on Mar 17, 2009 (gmt 0)

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



RewriteRule cannot 'see' query string data. You need a RewriteCond to examine the QUERY_STRING here.

Which URL are you linking to from your pages? Which URL should be be seeing and using to access the content? What is the local filepath inside the server for where the content really resides?

jdMorgan

12:12 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rewrite URL mysite.com/index.php?option=com_sobi2&tag=someword to filepath /Search.html?searchword=someword :

RewriteCond %{QUERY_STRING} &?tag=([^&]*)
RewriteRule ^index\.php$ Search.html?searchword=%1 [L]

Jim

g1smd

8:30 pm on Mar 18, 2009 (gmt 0)

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



The snippet with option_com in it looks like part of a URL as used by Joomla.

The question is therefore this... do you want to retain the old URLs as previously used by Joomla while switching to some new CMS that works differently to Joomla on the inside OR do you want to continue to use Joomla but change the URL format that users will see and use when they access the site?

Depending on the answer, it is possible that the rewrite needs to work in exactly the opposite direction to the example code posted immediately above.

Mark33

9:12 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



Thanks,jd but this only redirects me to my home page,without any rewriting.I mean,what I get is my home,but url is untouched.The one which should be rewritten.

g1 I'm not trying to migrate.What I'm trying to do is to make search strings from tags.Let me explain...
I use sobi2 component which is great great component,by the way.When I enter article,I enter meta keywords for that article as well.Sobi2 makes tags out of this meta keywords.

The problem is that those tags are just making loop back to same article too often,so they are almost useles.Even worse,sometimes all tags from article are just making loop back to same page.
So,I'm trying to mage search strings out of that tags,and bring some functionality to my site,and not being penalized by Google any more.
I get around 4000 unique visitors from Yahoo,but only around 300 from Google,and I think this might be the reason.We all know what Google thinks about two or more urls leading to same content.

My full urls look like this:

[mysite.com...]
to:
[mysite.com...]

So I need to rewrite all urls in way which replaces ?tag with Search.html?searchword.

I use SH404 SEF component,but those urls (tags) are untouched.

g1smd

9:23 pm on Mar 20, 2009 (gmt 0)

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



This is quite easy:

Input pattern from the requested URL is to be found from the

QUERY_STRING
by looking at
tag=(.*)

Internal server filepath target is

/Search.html?searchword=%1

A simple rewrite may be all you need here, as long as Search.html is a real physical file on the server, and can run scripts.

[edited by: g1smd at 9:35 pm (utc) on Mar. 20, 2009]

jdMorgan

9:32 pm on Mar 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two notes:

First, "Search.html" starts with an uppercase "S".

Second, it is very unlikely that "Search.html" is a real file. And if it is, then it won't accept query strings, because HTML files don't require or accept query strings.

There is probably a piece missing here, but the code I posted does exactly what was asked for.

Jim

Mark33

10:02 pm on Mar 20, 2009 (gmt 0)

10+ Year Member



Search.html is not a phisical file.

I can asure you that nothing is missing in those urls.They both work.First one is leading to the article(along with one more tag and "normal" article URL).

Second url is working too and it performes a standard joomla search.
I'm not sure why Search starts with uppercase letter,but I think SEF componet is to blame.

[edited by: Mark33 at 10:24 pm (utc) on Mar. 20, 2009]