.htaccess - how to redirect from root to subfolder? - apache

I have a website with URL www.somedomain.com
I want to redirect to a subfolder "folder", so that when you enter the website you are automatically redirected to www.somedomain.com/subfolder.
But I do not want the root directory to be changed, just simple redirection.
Is this possible with .htaccess ?
Is it possible to hide the /subfolder part from the URL also ?
Thanks

You can use a rewrite rule that uses ^$ to represent the root and rewrite that to your /store directory, like this:
RewriteEngine On
RewriteRule ^$ /store [L]
Just replace store with your directory

Related

Redirecting all trafic within a folder to a login.php file in another folder

How do I redirect all traffic from one folder to a file in another folder (eg. https://www.example.com/office/****** to https://www.example.com/folder/login.php)?
Try with below with mod_rewrite inside your folder where requests are coming,
RewriteEngine On
RewriteRule ^$ https://www.example.com/folder/login.php [R=301]
or with mod_alias on
Redirect / https://www.example.com/folder/login.php

.htaccess directory wildcard redirect

Please can someone tell me why this isn't working?
I am trying to redirect all files within the directory "Kent". In this example the page to be redirected is "ramsgate" and change the folder structure.
from:
/electrical-contractors/kent/ramsgate.php
to:
/electrical-contractors-ramsgate/
Using a wildcard redirect, why doesn't this work?
RedirectMatch 301 /electrical-contractors/kent/(.*).php /electrical-contractors-$1/
Have this rule inside /electrical-contractors/kent/.htaccess:
RewriteEngine On
RewriteRule ^(.+)\.php$ /electrical-contractors-$1/ [L,NC,R=301]

How to setup .htaccess rewrite url

how do I setup a redirect as follows:
Redirect these:
http://www.domain.com.au/browse-stores/storeA
http://www.domain.com.au/browse-stores/storeB
To these
http://www.domain.com.au/browse-stores?centre=storeA
http://www.domain.com.au/browse-stores?centre=storeB
Put this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^browse-stores/(.+)$ /browser-stores?centre=$1 [L,QSA]
If you actually wanted to redirect the browser so that the URL in the address bar changes, change the flags in the brackets to [L,QSA,R=301].

htaccess force redirect based on cookie not working for sub-directories

I have a folder for one of my domains /site. Here I have a .htaccess file with:
rewriteengine on
rewritebase /
rewritecond %{HTTP_COOKIE} !allow=asdx
rewriterule ^.*$ .set-cookie.php
Basicly I want to redirect all requests that do not have the allow cookie set to "asdx" to another file.
The problem is that I have folders like /site/subdomain1 that have .htaccess files of their own (with rewriteengine on). Accessing one of these files renders the initial redirect (based on the cookie) useless. If I disable the rewriteengine on directive from the sub-folders the cookie-based redirect works again.
How can I make the cookie-based redirect work without actually going to the individual subfolders and adding it there?
use the following for the rewrite rule:
rewriterule ^.*$ .set-cookie.php [R=302,L]

Url redirection subdirectory to subdomain

I am using php. and i want to redirect subdirectory to subdomain and subdirectory of subdirectory to subdomain directory.
For example : if i have url like http://www.test.com/test1/
then it should be redirect to http://test1.test.com/
and second if i have url like this http://www.test.com/test1/test2/
then it should be redirect to http://test1.test.com/test2/
Any one have idea how to do this.
Thanks in advance
can do in .htaccess with something like..
RewriteEngine On
RewriteRule ^([^/]+)/(.*)$ http://$1.test.com/$2 [R,L]