Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-02-2009, 06:13 AM   #1
LaoTzu
Confirmed User
 
Join Date: Feb 2004
Posts: 350
.htaccess question - query sting param redirect

$10 epass and my eternal gratitude for a working solution:

I need to 301 redirect urls with a specific query string parameter (any value) to my main url. In other words:

Code:
http://www.domain.com/index.php?cat=x
http://www.domain.com/index.php?cat=whatever
redirects to:
Code:
http://www.domain.com
(no file name (index.php), just the main domain.)

but
Code:
http://www.domain.com/index.php?dir=x
stays unchanged.
LaoTzu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 06:40 AM   #2
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
why use htaccess to do that? why not just use php?
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 06:54 AM   #3
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
put this at the top of your index.php

Certain values
PHP Code:
if (isset($_GET['cat'])) {
    switch (
$_GET['cat']) {
        case 
'x':
            
header("HTTP/1.1 301 Moved Permanently");
            
header("location: http://www.domain.com");
            
header("connection: close");
            break;
       case 
'whatever':
            
header("HTTP/1.1 301 Moved Permanently");
            
header("location: http://www.domain.com");
            
header("connection: close");
            break;
    }


Any Value
PHP Code:
if (isset($_GET['cat'])) {
    
header("HTTP/1.1 301 Moved Permanently");
    
header("location: http://www.domain.com");
    
header("connection: close");


Last edited by nation-x; 02-02-2009 at 06:58 AM.. Reason: added any value redirect
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 08:15 AM   #4
LaoTzu
Confirmed User
 
Join Date: Feb 2004
Posts: 350
Yo, you're awesome for posting that, but no dice. I tried the code in index.php but it had no affect. This script has so many .php functions and external files - totally beyond my grasp. That's why I was hoping for a neat and tidy .htaccess fix.
Hit me up with your epass though! mcurtis313 at gmail dot com
LaoTzu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 09:59 AM   #5
drocd
Confirmed User
 
Join Date: Aug 2007
Posts: 128
Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=.*$
RewriteRule .* http://www.domain.com [R=301,L]
__________________
230-699
drocd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 10:29 AM   #6
LaoTzu
Confirmed User
 
Join Date: Feb 2004
Posts: 350
Quote:
Originally Posted by drocd View Post
Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=.*$
RewriteRule .* http://www.domain.com [R=301,L]
So close!! The redirected URL is appended with the query string.
http://www.domain.com/?cat=x

I want to kill the trailing slash and query string for the canonical URL.
LaoTzu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 10:54 AM   #7
drocd
Confirmed User
 
Join Date: Aug 2007
Posts: 128
Okay, then change it to this:
Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=.*$
RewriteRule .* http://www.domain.com? [R=301,L]
__________________
230-699
drocd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 11:10 AM   #8
LaoTzu
Confirmed User
 
Join Date: Feb 2004
Posts: 350
WINNER!
I've still got the trailing slash (www.domain.com/) but that's damn close.
Hit me up with your epass mcurtic313 a t gmail d o t com
LaoTzu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 11:15 AM   #9
drocd
Confirmed User
 
Join Date: Aug 2007
Posts: 128
no epass needed. just hit me up if you need a programmer in the future.

note: even if you put the url in your browser without the trailing slash, you'll see it refresh WITH the slash.
__________________
230-699
drocd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-02-2009, 11:39 AM   #10
LaoTzu
Confirmed User
 
Join Date: Feb 2004
Posts: 350
You, sir, are the man. I will.
LaoTzu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.