开发者

Redirect request using .htaccess

I need to do the following Redirect using .ht开发者_Go百科access

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.


Try these rules:

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^$ subdirectory [L]


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜