简体   繁体   中英

htaccess redirect to www, subfolder and hide folder name

I'd like to redirect all requests, even non-www, to

www.site.com/public

but hide 'public' from the URL.

This code handles the www portion

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

and this redirects to /public

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

How can I combine them?

Have you access to VirtualHost ? If yes, you can set DocumentRoot .

Something like this

<VirtualHost *:80>
    DocumentRoot "path/to/public"
    ....
</VirtualHost>

And you don't need to do this with .htaccess. It is more clean solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM