Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
Marked

301 Redirect a Query String without a pattern

Recommended Posts

301 Redirect a Query String without a pattern

The following is how to redirect a URL which has query strings, and the new URL has no pattern.

 

Query strings, also called GET variables, are the variables visible in the URL. For example, index.php?f=10&page=5.

 

There are plenty tutorials out there they tell you how to redirect a query string to a URL which has a pattern. But I couldn't find one that expressly shows how to redirect query strings to a random URL.

 

 

Ok so here's how you can do it. Firstly you need a .htaccess file of course, that's where all this stuff goes. In it you must have this line first of all:

RewriteEngine On

 

Now for this tutorial I will use our own menu system. Say you have this URL:

http://www.rmxpunlimited.net/index.php?option=com_zoo&view=category&Itemid=227

And you want it to redirect to this:

http://www.rmxpunlimited.net/scripts/rmvx

 

In your .htaccess file you put the following:

RewriteCond %{QUERY_STRING} option=com_zoo&view=category&Itemid=227
RewriteRule ^index.php /scripts/rmvx? [R=301,L]

 

 

Hope this helps one random googler one day :)

Share this post


Link to post
Share on other sites

I can't say I know what all that means, but I'm sure it will help someone.

 

^~^

Share this post


Link to post
Share on other sites

I can't say I know what all that means, but I'm sure it will help someone.

 

^~^

haha i was just thinking the same thing :biggrin_002:

Share this post


Link to post
Share on other sites

I should try this on my home server.

I'm glad someone knows what it does :)

 

 

I can't say I know what all that means, but I'm sure it will help someone.

 

^~^

I'm just going to explain it even though you don't really care :P

 

Firstly, you can use a file named .htaccess in the root directly of your website to rewrite URLs and redirect certain URLs.

 

Secondly, there are two types of URLs that are used. The first is one using directories. For example: site/directory_1/final_directory/. Ok, redirecting this is simple. You can use the following in your .htaccess:

301 Redirect /site/directory_1/final_directory /new_directory

The 2nd type of URL is one with queries. This forum changed to friendly URLs but every single page used to be access using the index.php file. For example, my profile is forums/index.php?showuser=1. The first topic of the forum is accessed by forums/index.php?showtopic=1. Make sense? These URLs use queries or GET variables.

 

The .htaccess file cannot redirect a URL containing query strings using a 301 Redirect. This forum is about query strings that do not redirect to a pattern. Let me explain pattern. Usually these are used to create friendly URLs. For example:

site/index.php?page=1        ->site/page-1/  
site/index.php?page=2        ->site/page-2/  
site/index.php?page=3        ->site/page-3/  

As you can see the patter is site/page-{page number}/.

 

However what this tutorial is about is redirecting URLs to another URL that doesn't have any pattern. For example if I wanted to redirect my profile: forums/index.php?showuser=1, to a completely random page that has no relation to the original URL whatsoever, then I use the code in the first post. That's what it's all about.

 

 

I actually just learned this myself and wanted to document it and help anyone who had the same issue.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...