Question

I need to redirect a single Wordpress URL that is formatted like this: www.bluewidgets.com/?p=123 to a clean URL on another domain. How can I do this via .htaccess? All of the tutorials I've seen say that I need to specify another part of the url, like index.php, before the query string, but my URL doesn't have one - it's just the domain and then the query string.

Was it helpful?

Solution

Can't you just add to the header.php, before anything else:

<?php
if ($_GET['p'] == '123') {
    header('Location:http://www.yourotherdomain.com');
exit;
}
?>

I've done something similar in the past. It may not be pretty, but it works - I'd be interested to hear from more experienced PHP-ers whether it's a legitimate tactic.

OTHER TIPS

Try this rule:

RewriteCond %{QUERY_STRING} =p=123
RewriteRule ^$ /foo/bar? [L,R=301]

Or using REQUEST_URI:

RewriteCond %{REQUEST_URI} =/?p=123
RewriteRule ^$ /foo/bar? [L,R=301]

Note that the RewriteCond patterns begin with a = that identifies a lexicographical comparison instead of a regular expressions test. Additionally the empty query in substitution (denoted with …?) that will remove the originally requested query.

Doesn't wordpress already have built in URL prettyfication? Just out of curiosity why would you need to do this.

Aside from that, yes what you mention is how you'd do it via htaccess. Are you encountering an issue with this method?

A standard 301 redirect is in the format (and would be at domain1):

Redirect 301 /filename.php http://domain2.com/filename.php

but I just tried that with default permalinks and it didn't work.

On domain1, you could rewrite the URL with the standard wordpress rewrite block, and then immediatly redirect it tp domain2. Messy, but it might work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top