logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_rewrite rule to prevent access to a specific page ?
Author
fitzgerac



Joined: 24 Jun 2013
Posts: 12

PostPosted: Tue 25 Jun '13 16:46    Post subject: mod_rewrite rule to prevent access to a specific page ? Reply with quote

Hi all. Could someone give me a little advice with this mod_rewrite rule I'm trying to create. I am very new to Apache admin. Here's the issue:
I have 3 vhosts running on my HTTPD Apache 2.2.24 server: Server1, Server2, Server3. Each vhost is connected to a Weblogic application server. We are trying to prevent access to the Example.portal page on each application server. So the URLs I'm trying to rewrite are:
- Server1.domain.com/PortalWeb/Example.portal
- Server2.domain.com/PortalWeb/Example.portal
- Server3.domain.com/PortalWeb/Example.portal

So, I would like to redirect the above URLs back to the 'root' of the website. ie: server1.domain.com. Here is my rewrite rule:
RewriteRule ^(.*)/Example\.portal$ http://$1 [NC]

So, the rule is matching correctly to URLs that contain Example.portal, however the back reference from (.*) does not seem to map to $1.

Can anybody offer any advice? Thanks!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3118
Location: Hilversum, NL, EU

PostPosted: Tue 25 Jun '13 17:12    Post subject: Reply with quote

You can try some like with variable HTTP_HOST:

RewriteRule /(.*)/Example\.portal(.*) http://%{HTTP_HOST}/$1 [L,R=301,NC]

When SSL or no SSL you can play with:

RewriteCond %{HTTPS} !=on


Steffen
Back to top
fitzgerac



Joined: 24 Jun 2013
Posts: 12

PostPosted: Tue 25 Jun '13 17:58    Post subject: Reply with quote

Wow, thanks Steffen. That worked like a charm. Although, I don't understand why...
Back to top
fitzgerac



Joined: 24 Jun 2013
Posts: 12

PostPosted: Wed 26 Jun '13 0:10    Post subject: not completely working. Reply with quote

Hey steffen (or anybody)... I guess this rewrite rule still isn't completely working. Here is the rule as I have it now:

RewriteRule ^(.*)/Example\.portal/(.*)$ http://%{HTTP_HOST}$1 [L,R=301,NC]

And the rule is working when the request is for Server1.domain.com/Example.portal and
Server1.domain.com/Example.portal/SubFolder/Example.html
but doesn't seem to work for
Server1.domain.com/SubFolderPortalWeb/Example.portal

Any ideas out there? thanks in advance.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3118
Location: Hilversum, NL, EU

PostPosted: Wed 26 Jun '13 8:15    Post subject: Reply with quote

Try to remove first slash in the rule: ...^(.*)Example\.....

Steffen
Back to top
fitzgerac



Joined: 24 Jun 2013
Posts: 12

PostPosted: Wed 26 Jun '13 17:30    Post subject: Reply with quote

Thanks again Steffen, but that still doesn't work. I think the problem with the rule:
RewriteRule ^(.*)Example\.portal(.*)$ http://%{HTTP_HOST}$1 [L,R=301,NC]
is that the second (.*) will match only if there are more characters after Example.portal. However, in the case of the URL Server1.domain.com/SubFolderPortalWeb/Example.portal
there are no more characters after Example.portal, so the second (.*) doesn't match.
Is there a special character that represents any character including no characters?

thanks in advance again!
Back to top
admin
Site Admin


Joined: 15 Oct 2005
Posts: 702

PostPosted: Thu 27 Jun '13 11:07    Post subject: Reply with quote

Try to add an second rule with the last (.*) removed.
Back to top


Reply to topic   Topic: mod_rewrite rule to prevent access to a specific page ? View previous topic :: View next topic
Post new topic   Forum Index -> Apache