rewritemap based redirection

Using a single web hosting account to host multiple sites

rewritemap based redirection

Postby pramodpmenon » Thu Jul 23, 2009 10:11 pm

I am trying a rewritemap for my domain.

We have urls like example.com/web/redirect?location=(parameter)


This url will redirect to the page mentioned in the paramater.The list of allowed domains for the parameter should come from a rewrite map. All other domains values shoud be redirected to error page.


I worked on this rewritemap. But it is not reaching anywehere.
Code: Select all
RewriteMap allowhost txt:/usr/apache2/conf/allowhost.txt


RewriteCond %{QUERY_STRING} ^location=(.*)[NC]


RewriteCond ${allowhost:%{%1}|NOT-FOUND} !NOT-FOUND


RewriteRule ^/web/redirect /error.html [R=301,L]


allowhost.txt File contents
Code: Select all
http://www.domaina.com NOT-FOUND
http://www.domainb.com NOT-FOUND
pramodpmenon
 
Posts: 2
Joined: Thu Jul 23, 2009 5:28 am

Postby richardk » Fri Jul 24, 2009 12:42 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap allowhost txt:/usr/apache2/conf/allowhost.txt

# Only match the domain part.
RewriteCond %{QUERY_STRING} ^(.*&)?location=(http://[^/&]+) [NC]
# It will return FOUND if it is found.
RewriteCond ${allowhost:%2|NOT-FOUND} !^FOUND$
# If it wasn't found it will be sent to /error.html.
RewriteRule ^/web/redirect$ /error.html [R=301,L]

and
Code: Select all
http://www.domaina.com FOUND
http://www.domainb.com FOUND
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Not working

Postby pramodpmenon » Mon Jul 27, 2009 3:17 am

Hi Richard,
Thanks for the reply. Unfortunaltely it is not working.
It is getting redirected for all domains.
I put following:-
RewriteMap allowhost txt:/usr/apache2/conf/allowhost.txt
RewriteCond %{QUERY_STRING} ^(.*&)?location=https?://(.*) [NC]
RewriteCond ${allowhost:%2|NOT-FOUND} !^FOUND$
RewriteRule ^/web/redirect$ /error.html [R=301,L]


I guess the first match itself is not working. I have put loglevel as 9. I see following in rewrite log.
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#155a30/initial] (2) init rewrite engine with requested uri /
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#155a30/initial] (3) applying pattern '^/(.*)\.htm$' to uri '/'
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#155a30/initial] (3) applying pattern '^/web/redirect$' to uri '/'
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#155a30/initial] (1) pass through /
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#153a28/subreq] (2) init rewrite engine with requested uri /v2/index.html
127.0.0.1 - - [27/Jul/2009:16:42:49 +051800] [localhost/sid#e8238][rid#153a28/subreq] (1) pass through /v2/index.html
127.0.0.1 - - [27/Jul/2009:16:43:27 +051800] [127.0.0.1/sid#e8238][rid#15fa58/initial] (2) init rewrite engine with requested uri /error.html
127.0.0.1 - - [27/Jul/2009:16:43:27 +051800] [127.0.0.1/sid#e8238][rid#15fa58/initial] (3) applying pattern '^/(.*)\.htm$' to uri '/error.html'
127.0.0.1 - - [27/Jul/2009:16:43:27 +051800] [127.0.0.1/sid#e8238][rid#15fa58/initial] (3) applying pattern '^/web/redir$' to uri '/error.html'
127.0.0.1 - - [27/Jul/2009:16:43:27 +051800] [127.0.0.1/sid#e8238][rid#15fa58/initial] (1) pass through /error.html
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (2) init rewrite engine with requested uri /Home.htm
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (3) applying pattern '^/(.*)\.htm$' to uri '/Home.htm'
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (4) RewriteCond: input='/Home.htm' pattern='!^/web/' => matched
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (2) rewrite /Home.htm -> /web/Home.htm
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (2) explicitly forcing redirect with http://localhost/web/Home.htm
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (3) applying pattern '^/web/redirect$' to uri 'http://localhost/web/Home.htm'
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (1) escaping http://localhost/web/Home.htm for redirect
127.0.0.1 - - [27/Jul/2009:16:45:07 +051800] [localhost/sid#e8238][rid#155a30/initial] (1) redirect to http://localhost/web/Home.htm [REDIRECT/302]
pramodpmenon
 
Posts: 2
Joined: Thu Jul 23, 2009 5:28 am

Postby richardk » Mon Jul 27, 2009 8:19 am

The RewriteLog you posted does not contain any requests for /web/redirect?location=http://www.domaina.com.

Post your whole mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron