Mobile app version of vmapp.org
Login or Join
Tiffany637

: How to redirect URLs with a specific IDs to new URLs on a new domain name? I want to redirect all pages where there is a specific word inside in the URL. Both websites have the same articles.

@Tiffany637

Posted in: #301Redirect #Apache #Htaccess #Redirects

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 videos.example.com.ph and the word its-showtime inside should be redirected to the same article on example.com.ph/
If this is too difficult, a redirect to example.com.ph mainpage would be ok too.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Tiffany637

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme