简体   繁体   中英

Exclude folder in htaccess from www redirect

I have a www redirect in my .htaccess:

RewriteCond %{HTTP_HOST} example\.com
RewriteRule ^(.*)$ http://www.example/ [R=permanent]

Now I would like to exclude one folder to use the above redirect. I would like to access a folder without being redirected to the domain with www. For example: What I want: example.com/test What happens: www.example.com/test

Can I exclude only the folder test?

You can use:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule !^test/ http://www.%{HTTP_HOST}/%{REQUEST_URI} [L,NC,NE,R=302]

Make sure this rule is first rule just below RewriteEngine On line your root .htaccess (one directory level above /test/ ).

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