• Hi guys

    This is driving me somewhat mad, setting a site live and I am adding in all the 301 redirects but hit on a problem.

    The old site uses this structure:
    http://thedomain.com/?Section=page&p=/areasofexpertise/
    etc…

    The issue is nothing I do can stop this from loading the page as index.php as if it were the blog homepage.

    I have tried:
    redirection plugin – no joy so disabled.
    .htaccess:

    Redirect 301 /?Section=page&p=/areasofexpertise/ http://www.thedomain.com/whatever
    
    RewriteEngine On
    ...

    Also tried intercepting it as a rewrite rule but i 500’d it as i think i got the regular expression syntax wrong so simply tried a normal rewrite and that does not work either e.g.

    RewriteEngine On
    RewriteRule ^/whoweare/$ http://www.thedomain.com/whatever [R=301,L]
    RewriteBase /
    ...

    Any ideas?

    I even encoded my own redirecter in 404.php but ofc in this case WP is not 404’ing and 1. its query string data on the root and 2. it has p= a querystring WP uses (this is why blog index is loading’

    half a mind just to give up and let their SEO die 😀

Viewing 1 replies (of 1 total)
  • Thread Starter latro666

    (@latro666)

    Ok so I worked out an out of the box (dodgy) solution to this for future searchers.

    First off I intercepted any ?p= in htaccess and rewrite as a server 404. We are using url rewriting so p= should never come up (this is dodgy as hell but meh)

    RewriteCond %{QUERY_STRING} /?p=(\d*)
    RewriteRule ^$ *? [R=404,L]

    I then in htaccess reset which file the server looks to for 404s:

    ErrorDocument 404 /wp-content/x-redirector.php

    I created this file and setup my own key value redirection script:

    <?php
    	$url = $_SERVER['REDIRECT_URL'];
    	$qs = $_SERVER['REDIRECT_QUERY_STRING'];
    
    	if($qs != ''){
    		$url = $url . "?" . $qs;
    	}
    
    	//page in wordpress with page not found msg
    	$endurl = '/page-not-found';
    
    	//array of redirects
    	$redirects = array();
    	$redirects['/?Section=page&p=/areasofexpertise'] = '/whatever/';	
    
    	foreach($redirects as $key => $value){
    		if($key == $url ||  $key . '/' == $url){
    			$endurl = $value;
    		}
    	}
    
    	Header( "HTTP/1.1 301 Moved Permanently" );
    	Header( "Location: $endurl" );
    ?>

    Cycles the redirects and if it gets a hit it changes the forwarding url if it does not find a match then it goes to /page-not-found which is a WordPress page.

    not very efficient or elegant but it works 😀

Viewing 1 replies (of 1 total)

The topic ‘Base url redirects with a p= querystring’ is closed to new replies.