GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   .htaccess question - query sting param redirect (https://gfy.com/showthread.php?t=885266)

LaoTzu 02-02-2009 06:13 AM

.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.

nation-x 02-02-2009 06:40 AM

why use htaccess to do that? why not just use php?

nation-x 02-02-2009 06:54 AM

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");



LaoTzu 02-02-2009 08:15 AM

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

drocd 02-02-2009 09:59 AM

Code:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=.*$
RewriteRule .* http://www.domain.com [R=301,L]


LaoTzu 02-02-2009 10:29 AM

Quote:

Originally Posted by drocd (Post 15422480)
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.

drocd 02-02-2009 10:54 AM

Okay, then change it to this:
Code:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=.*$
RewriteRule .* http://www.domain.com? [R=301,L]


LaoTzu 02-02-2009 11:10 AM

WINNER!
I've still got the trailing slash (www.domain.com/) but that's damn close.
Hit me up with your epass :thumbsup mcurtic313 a t gmail d o t com

drocd 02-02-2009 11:15 AM

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.

LaoTzu 02-02-2009 11:39 AM

You, sir, are the man. I will.


All times are GMT -7. The time now is 11:36 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123