简体   繁体   中英

how to set htaccess to only allow www and dev

I have a server and I'm trying to setup a dev and production environment but when the production server is live is allowing any random subdomain on the request url like:

abc.example.com

and I wanna to allow only www and dev, this is my .htaccess settings:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^dev\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.example.com%{REQUEST_URI} [R=301,L]

Is there a way to achieve that and is my htaccess ok?

This might work:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^dev\. [NC]
RewriteRule ^ %{REQUEST_SCHEME}://www.example.com%{REQUEST_URI} [R=301,L]

apache variable %{REQUEST_SCHEME} passes http or https according to your request.

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