Author |
|
fitzgerac
Joined: 24 Jun 2013 Posts: 12
|
Posted: Tue 25 Jun '13 16:46 Post subject: mod_rewrite rule to prevent access to a specific page ? |
|
|
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
|
Posted: Tue 25 Jun '13 17:12 Post subject: |
|
|
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
|
Posted: Tue 25 Jun '13 17:58 Post subject: |
|
|
Wow, thanks Steffen. That worked like a charm. Although, I don't understand why... |
|
Back to top |
|
fitzgerac
Joined: 24 Jun 2013 Posts: 12
|
Posted: Wed 26 Jun '13 0:10 Post subject: not completely working. |
|
|
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
|
Posted: Wed 26 Jun '13 8:15 Post subject: |
|
|
Try to remove first slash in the rule: ...^(.*)Example\.....
Steffen |
|
Back to top |
|
fitzgerac
Joined: 24 Jun 2013 Posts: 12
|
Posted: Wed 26 Jun '13 17:30 Post subject: |
|
|
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
|
Posted: Thu 27 Jun '13 11:07 Post subject: |
|
|
Try to add an second rule with the last (.*) removed. |
|
Back to top |
|