Display Content Of Website One On Website Two - .htaccess

I've built a blog which contains multiple categories, which span multiple niches, and would like to split/group several categories over several url's.
So I have:
website-one.com/blog/category.php?name=$1&page=$2, which rewrites to website-one.com/blog/music/1.
So lets assume I have:
website-one.com/blog/music/1, website-one.com/blog/fashion/1 and website-one.com/blog/sport/1.
I want to be able to use the same website but to mirror the content on a completely sepperate domain:
website-two.com/blog/cooking/1.
So I'm not looking to completely copy one site on another, but select the categories I'd like to display on each domain, using website one as the main administrative site.
Is it possible to achieve this with a simple rewrite rule or server side scripting?
My concern comes with the pagination, meaning that when people click on the Next Page button they are not redirected back from domain two to domain one (website-two.com/blog/cooking/1 to website-one.com/blog/cooking/2).

In .htaccess on website-one.com add cooking/1 rewrite to second domain
RewriteRule ^blog\/cooking\/1$ http://website-two.com/blog/cooking/1 [R=301,L]
In .htaccess on website-two.com add cooking/2 rewrite back to first domain
RewriteRule ^blog\/cooking\/2$ http://website-one.com/blog/cooking/2 [R=301,L]

Related

How to ignore/redirect all URLs matching a certain string

I am using the Wordpress plugin, Timely All-in-One events calendar. Unfortunately it is creating a plethora of duplicate URLs which end in strings like (https://www.mywebsite.com/events/action~agenda/page_offset~-2/request_format~json/cat_ids~4) or (https://www.mywebsite.com/events/action~oneday/exact_date~2-4-2019/) for example.
As a consequence of these URL directives each being for a different calendar view but containing the same webpage title and content, some search engines are seeing this as duplicate content. Whilst robots.txt is setup to tell bots to ignore the URLs containing said strings, some crawlers are ignoring robots.txt. I have also disabled the various different calendar views so there is now only the agenda view but even in spite of this, bots continue to crawl these URLs.
Therefore is it possible to use Apache/ a .htaccess directive to tell the server to direct any requests containing "/action~" to either remove the string from the URL so the browser just reads "/events/" or to redirect/forward the URLs to another page.
There are over 500 of these URLs so I ideally would like a quick remedy!
Thanks in advance.
Check this rewrite in your .htaccess file
RewriteEngine On
RewriteRule ^events\/action(.*)$ /events/ [L,R=301]

What is the correct method to 301 redirect 500+ pages

I need to redirect 500+ pages. The original url references the product id, now they want it to reference the product name. For example:
from:
www.thedomain.com/bn/products/product-details/72
to:
www.thedomain.com/bn/products/product-details/MR633
I know the rewrite rule needs to be:
RewriteRule ^/bn/products/product-detail/72$ http://www.thedomain.com/bn/products/product-detail/MR633 [R=301]
Will I need to create all 500+ redirect lines manually to add to the htaccess file, or is there a different, better approach? Google has indexed all 500+ pages, so they don't want to lose that juice. Any recommendations would be appreciated.
Also, is it OK/normal to have hundreds of redirects in an .htaccess file?

using mod_rewrite to create SEO friendly URLS

I've been searching google for this but can't find the solution to my exact needs. Basically I've already got my URL's named how I like them i.e. "http://mysite.com/blog/page1.php"
What I'm trying to achieve (if it's possible!) is to use rewrite to alter the existing URLS to: "http://mysite.com/blog/page1"
The problem I've come across is I've found examples that will do this if the user enters "http://mysite.com/blog/page1" into the broweser which is great, however I need it to work for the existing links in google as not to loose traffic, so incoming URLS "http://mysite.com/blog/page1.php" are directed to "http://mysite.com/blog/page1".
The 1st example (Canonical URLs) at the following is pretty much what you want:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#url
This should do the trick, rewriting requests without .php to have it, invisible to the user.
RewriteEngine On
RewriteRule ^/blog/([^.]+)$ /blog/$1.php
You will need to write a rewrite rule for mapping your old url's to your new url as a permanent redirect. This will let the search engine know that the new, seo friendly url's are the ones to be used.
RewriteRule blog/page1.php blog/page1 [R=301,L]

htaccess rewrite question

I need to redirect incoming requests for a page to a subdirectory whilst keeping the URL displayed as originally typed.
This is to manage language pages easier.
For example, I want Spanish pages to be under www.mydomain.com/es. I want the URL displayed to remain www.mydomain.com/es.
But the actual page is held here - www.mydomain.com/international/es
This means I can keep my root folder tidy and have all the language pages in one directory. But I want it to be easy for language specific visitors to find thier page.
Can anyone point me in the right direction? I've had a go but to be honest I always manage to produce server errors and get in a mess.
Many thanks
TT
Provided you are on an apache server look up mod_rewrite.
Example for your .htaccess:
RewriteEngine on
RewriteRule ^es/([0-9a-zA-Z\/]*)$ /international/es/$1 [L]

.htaccess redirect question

I have a slight problem with .htaccess redirect.
I have a dynamic site with 2 levels of variables - content="type -(alpha)" and ID="number" but this is very not seo friendly what I really would like to create is a rewrite rule that generates a "friendly" url for serach engines & users alike. Very much like WordPress does.
Each ID is already unique (obviously) and on creation is creating a unique "permalink" field so for example ID=1 has a "permalink field" as "2009/10/27/page title" and ID=100 would be "2010/10/27 page title".
I would like folder/wall.php?content=type&ID=number to redirect to folder/permalink.php/html/htm (don't mind a non dynamic extension)
Any clues? - this is not right (I know) but it also "breaks" my css file
RewriteEngine On
RewriteRule wall/content/(.*)/ID/(.*)/ wall.php?content=$1&ID=$2
RewriteRule wall/content/(.*)/ID/(.*) wall.php?content=$1&ID=$2
You need to make sure you have a URL convention that won't conflict with other files on the server. For example, if your page is displaying "Products" and you don't have an actual folder in the root of your server called /products/, you could do this
RewriteEngine On
RewriteRule ^products/([^/\.]+)/([^/\.]+)/?$ wall.php?content=$1&id=$2 [L,NC,QSA]
Replace "products" in this example with whatever name is most appropriate for what your wall.php page does.
This would equate to the following URL
www.yoursite.com/products/title/29/
Which would rewrite to
www.yoursite.com/wall.php?content=title&id=29

Resources