How to redirect URLs with a specific IDs to new URLs on a new domain name?
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, redirects, apache, 301-redirect, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :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'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?
Comments
Post a Comment