views:

34

answers:

2

I worked on a website for which I had a "development URL" that looked something like this:

www.example.com.php5-9.dfw1-2.example.com/

Now, several weeks after the website launch, there is at least one page of content indexed on Google with that URL.

Question: How do I redirect all requests from that test URL to reroute to the actual domain?

So, for instance, I would want:

www.example.com.php5-9.dfw1-2.example.com/page-name

To go to:

www.example.com/page-name

The website is powered by WordPress and hosted on a PHP server. I've experimented with .htaccess without much success.

+1  A: 

Considering that your primary motivation for this issue is the fact that Google indexed your pages on the test server, I believe that trying to use the mod_rewrite functionality to keep those links active is a bit redundant (and fiddly).

Instead, I would suggest using Google's Webmaster Tools, and register under both the testing location and the production location. You should then be able to request the URLs under the Testing Subdomain be removed, and also request the Production URL to be crawled (thereby removing the Test links and replacing them with Production links).

Lucanos
A: 

If www.example.com is ought to be the only valid host name on your server, you can use this rule to force this host name:

RewriteCond %{HTTP_HOST} !^(www\.example\.com|)$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.example.com%{REQUEST_URI} [L,R=301]

Otherwise try this rule to redirect just this specific host name:

RewriteCond %{HTTP_HOST} =www.example.com.php5-9.dfw1-2.example.com
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.example.com%{REQUEST_URI} [L,R=301]

You might additionally check the request method in REQUEST_METHOD since this rule will match any method (GET as well as POST).

Gumbo
That is working _excellently_ and, at a base, is exactly what I'm after. Is there a way to have it redirect the pages as well?For instance:www.example.com.php5-9.dfw1-2.example.com/parent-url/child-urlWould reroute to:www.example.com/parent-url/child-url
Jonathan Wold
@Jonathan Wold: That was supposed to happen. So what happens instead?
Gumbo
@Gumbo: All requests take them straight to the root domain.
Jonathan Wold
@Jonathan Wold: Are you using any other rules that can conflict with this one?
Gumbo
@Gumbo: It is powered by WordPress, so we have the standard WordPress rules as follows: # BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>
Jonathan Wold
@Jonathan Wold: Try to put this rule above those of Wordpress.
Gumbo
@Gumbo That worked! Thank you so much :).
Jonathan Wold