views:

22

answers:

2

I need to do the following Redirect using .htaccess

http://example.com => https://example.com/subdirectory
http://www.example.com => https://example.com/subdirectory
https://example.com => https://example.com/subdirectory
https://www.example.com => https://example.com/subdirectory

but i do not want to show sub directory in address bar the url should be https://example.com my site files lives in sub directory but i need to hide it in address bar for every request.

+1  A: 

Try these rules:

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^$ subdirectory [L]
Gumbo
but it show the subdirectory name in address bar and https://example.com doesn't redirect to https://example.com/subdirectory
JKS
A: 

How about this (building on Gumbo's answer):

RewriteEngine On

# Redirect direct subdirectory/ request to main domain
RewriteCond %{THE_REQUEST}  ^(POST|GET)\s/subdirectory
RewriteRule ^subdirectory/?(.*)$ https://example.com/$1 [R=301,L]

# Redirect www/non-https to https://example.com
RewriteCond %{HTTPS}       !=on           [OR]
RewriteCond %{HTTP_HOST}   !=example.com
RewriteRule ^.*$ https://example.com/$0 [R=301,L]

# Redirect (internally) to subdirectory/
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteRule ^.*$ subdirectory/$0 [L]
Tim Stone