Implementing 301 redirects in sub-folder of Silverstripe - .htaccess

I am trying to create 301 redirects from a silverstripe subdirectory to a new site/subdomain on different server, can't seem to make it work!
So need www.researchnutrition.com.au/practitioner redirecting to www.practitioner.researchnutrition.com.au
along with a number of other urls within the practitioner subfolder specified to new pages on new domain.
Have tried several combinations or rewrite/redirect rules but nothing seems to be taking effect.
Also should the .htaccess file where I make the changes need to sit within the root folder or within the /practitioner folder.
Thanks so much in advance.

You can use .htaccess file in the practitioner folder:
RewriteEngine on
RewriteRule (.*) http://www.practitioner.researchnutrition.com.au/$1 [R=301,L]

Another option is just creating a redirection page in the cms and redirecting that to an external url (which is, despite the option saying "redirect to internal page", possible).

Related

Htaccess and redirect all content of folder, but exlude the main folder

I got the following urls:
domain.com/categoryA/articleA
domain.com/categoryA/articleB
I want to redirect:
domain.com/categoryA/articleA -> domain.com/categoryB/articleA
domain.com/categoryA/articleB -> domain.com/categoryB/articleB
but leave it as it is and do not redirect the main folder: domain.com/categoryA/
I tried to use the rule:
RewriteRule ^categoryA/(.*)$ /categoryB/$1 [R=301,NC,L]
but it also redirect domain.com/categoryA/ to domain.com/categoryB/
How to exclude from the above rewrite rule the redirection of the main folder (categoryA), but still redirect all that is in the folder (and then change also the root folder)?
I am looking for a solution that is SEO friendly (I got the same articles in two categories, but want still to have indexed domain.com/categoryA, but the rest only as domain.com/categoryB/xxx.
Best Greetings,
Mat
With your shown samples/attempts, please try following Rules in your .htaccess file. Please make sure to place this rule under your domain redirect rule(if its there), also make sure to clear your browser cache before testing your URLs.
RewriteRule ^categoryA/([\w-]+)/?$ /categoryB/$1 [R=301,NC,L]

How can I create friendly url redirection made form absolute url's in .htaccess?

I'm writing a program that creates custom friendly urls for websites in .htaccess file. The problem is that I want to create redirect from absolute friendly url to another absolute "real" url, because .htaccess file is placed in root directory and websites are placed in many different child directories.
If the pages were placed in the same folder, I could do something like this:
RewriteEngine On
RewriteRule site site.php
RewriteRule site-two site-two.php
but the pages are placed in different child folders, so the above code doesn't work.
I tried to do something like this but it doesn't work:
RewriteEngine On
RewriteRule http://www.randomdomain.com/sites-dir/site/ http://www.randomdomain.com/content/sites-dir/site.php
RewriteRule http://www.randomdomain.com/sites-dir/site-two/ http://www.randomdomain.com/content/sites-dir-two/site-two.php
I would not like the solution to be similar to 301 redirect because with it, .htaccess refers to another page, but does not save the friendly address in the url bar.
I also want linking pages using a friendly url to be possible.
Does anyone know the solution to this problem?
Thank you in advance for your answer.

Website pages with slashes

Just building a site using php. I would like to know how to create pages without having to make ".php" links for every page. For example I want to build the site to be as follows: www.mysite.com/products instead of www.mysite.com/products.php. (Further example www.mysite.com/products/headphones )
An example of what I am looking for is as follows: http://www.starbucks.ca/store-locator
Any idea how starbucks is doing this? It isn't making a separate folder and index for every page is it?
Thanks in advance!
Jason
You can use URL rewriting to do this. You can create a .htaccess file, place it in the root directory of your website with the following content (as an example):
RewriteEngine On
RewriteRule ^tutorial/([0-9]+)/$ index.php?tutorial=$1
RewriteRule ^page/store-locator/$ index.php?page=store-locator
RewriteRule ^$ index.php
These are some basic rules that tell the web server to rewrite a URL without .php to a URL that does have .php.
In the above example, when you are visiting example.com/tutorial/3/, it will actually visit example.com/index.php?tutorial=3 and then your index.php will display the contents. It's similar for the store-locator page.

htaccess selective redirect

I am trying to redirect all sub-directory pages to main directory, except of a few pages (e.g. (somepage1.html).
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(de|ru)/somepage1.html
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$2 [R=301,L]
Everything working except de/somepage1.html is redirected to home page (/), which is not acceptable. I wont it not redirected at all.
How can I achieve it
Thanks1
Well above rules are clearly excluding de/somepage1.html URL so it is most likely some other rule that is redirecting de/somepage1.html to /. Are you using wordpress or some other CMS tool by any chance? That might have its own rules in .htaccess file, check that please.
Also it would help to check web server's access log when this redirection happens.
the code I provided is working perfectly, so if somebody looking for this kind of a solution can use it without a fought.
The reason for not working is that my website were keeping cash and therefore was not renew frequently.

How can I use .htaccess to redirect a folder on my website to a folder on another website?

I'm trying to have everything in this folder on my website - http://www.mywebsite.com/media/images/* redirect to another website with the same structure i.e. http://www.theotherwebsite.com/XXX/media/images/* using .htaccess
Even simpler, it can be accomplished by Redirect alone, no need to use Rewrite.
Redirect permanent /media/images http://foobar.com/new/location
Okay... managed to figure this one out...
RewriteRule ^media/images/(.*)$ http://www.theotherwbsite.com/XXX/media/images/$1 [L]

Resources