You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Alexandru Duzsardi <al...@pitechnologies.ro> on 2017/09/20 06:09:44 UTC

[users@httpd] Restrict access to site pages except specific url

Hi guys,

I'm trying to configure apache 2.4 to allow access only to a specific set of
pages when accessed through a hostname.

 

So i have two virtualhosts configured , both pointing to the same physical
path/site.

Let's say www.mainsite.com <http://www.mainsite.com>  and blog.mainsite.com
.

There are categories for different sections of the site like /news ,
/contact , /blog and so on.

What i would like is that when the site is accessed through
blog.mainsite.com , only the subpages under /blog to be accessible like
/blog/artile-url. , when accessing blog.mainsite.com to be automatically
redirected to /blog , and any other page except /blog(/?artilec-url) to be
also redirected back to /blog

 

 

I've tried with 

RewriteCond  %{ REQUEST_URI}             !/blog/?.*

RewriteRule ^$                http://%{ HTTP_HOST}/blog [R=302,L]

 

But this creates a redirect loop and not sure how to break out of it. I know
that RewriteRule is evaluated first , and how i translate this rules is when
accessing the site redirect the client to /blog , next evaluate the
condition if requested URL does not contain /blog apply the rewriterule else
do nothing.