3

I want to redirect all pages where there is a specific word inside in the URL. Both websites have the same articles.

For example:

videos.example.com.ph/its-showtime-hashtags-hashtags-and-dawns-popular-dance-moves_966aaafd8.html

should be redirected to

example.com.ph/its-showtime-hashtags-hashtags-and-dawns-popular-dance-moves_8a4521384.html

The difference is the Domain and the ID at the end. All articles with the URL http://videos.example.com.ph and the word its-showtime inside should be redirected to the same article on http://example.com.ph/

If this is too difficult, a redirect to example.com.ph mainpage would be ok too.

  • You can redirect a single URL of a known ID, but you can't do a general redirect for "all articles" that have different IDs - if that is what you require? How do you map the source ID (eg. 966aaafd8) to the target ID (eg. 8a4521384)? Or is the redirect with a different ID just a "special case"? – MrWhite Jan 3 '16 at 10:57
  • the IDs are differnet but the url is the same. only teh domain and teh ID are different. The easierst way would be to redirect to the mainpage. I'm ok with this too – Aesir John Jan 3 '16 at 11:17
4

You can't do a simple redirect of "all articles" if the source and destination IDs in the URL are different and there is no easy way to map between the two. For example, how do we know that 966aaafd8 maps to 8a4521384?

In order to do this you would need to create a RewriteMap in your server config (containing all the source / destination IDs) or rewrite requests to another script that performs the lookup and then redirects.

However, you can redirect all requests to the document root on the other domain if that is OK. But this is generally a bad user experience (and hence bad for SEO), if that is a concern.

At the top of your .htaccess file in the videos.example.com.ph subdomain:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} =videos.example.com.ph [NC]
RewriteRule ^its-showtime http://example.com.ph/ [NC,R=302,L]

If the videos.example.com.ph subdomain and the main domain are physically hosted in at different places then you can remove the RewriteCond directive.

Note that this matches its-showtime at the start of the URL (as in your examples). If you need it to match anywhere in the URL, then just remove the ^ prefix.

Note also that this is a case-insensitive match (NC - NOCASE) - if this is not required then remove the NC flag from the RewriteRule. (The NC flag on the RewriteCond should remain, as this simply catches malformed requests that would otherwise still resolve.)

Change the 302 (temporary) redirect to 301 (permanent) redirect when you are sure it's working OK - assuming this should be a permanent redirect?

  • Just added but no result videos.showtime.com.ph/its-showtime-energetic-performance-from-its-showtime-family_2f1982c3c.html should be go to showtime.com.ph – Aesir John Jan 3 '16 at 12:11
  • Absolutely nothing happened? Just try entering any gibberish at the top of your .htaccess file. This should trigger a 500 Internal Server Error, however, if you still get nothing then your .htaccess file is not being processed. – MrWhite Jan 3 '16 at 12:14
  • 1
    I put it at the end and not at the top. Sorry my mistake. Works very well. Thank you – Aesir John Jan 3 '16 at 12:15
  • Can't tell you how many times I've tried looking up an old article on a news site and instead of responding with "404" or "301", the site just plops me either to "/notfound.404" or "/". WHAT IDIOT PROGRAMMED THIS!?" – Cole Johnson Jan 8 '16 at 1:32
  • Maybe some videos are not available anymore. We have to check this manually and this takes a lot of time because there are 6000 videos published. Sorry for this issue :) – Aesir John Jan 22 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.