You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jason Williard <jw...@pcsafe.com> on 2006/01/19 21:57:49 UTC

[users@httpd] Troubles w/mod_rewrite

I have a site that shows weather forecasts.  I would like create a
RewriteRule to redirect to the proper URL when someone appends their zipcode
to the base url.

i.e. http://weather.domain.com/12345 ->
http://www.domain.com/cgi-bin/weather/weather.pl?zip=12345

So far, I have tried several methods but cannot get it to work.  Here are my
current rules in the .htaccess file:

RewriteEngine   On
RewriteRule     ^/([^/]*)
http://www.domain.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]

I have also tried each of the following:

RewriteRule     ^/([^/][0-9])
http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
RewriteRule     ^/([^/][0-9]{5})
http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
RewriteRule     ^/([0-9]{5})
http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
RewriteRule     ^/([0-9])
http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]

None of these have worked.  I simply get a 404 Not Found error.  However, I
know that mod_rewrite is working as I had another rule in place for
redirecting anything that goes to that page to the default URL. 

Any ideas?

---
Thank You,
Jason Williard


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Troubles w/mod_rewrite

Posted by Joshua Slive <jo...@slive.ca>.
On 1/19/06, Jason Williard <jw...@pcsafe.com> wrote:
>
> You were right... As soon as I removed the leading slash, the problem was
> solved.  But now I have another issue...
>
> While I want this rewrite to occur, I also want everything else to redirect
> to a default URL.  To do this, I added the following:
>
> RewriteRule     ^([0-9]{5})   http://.../weather.pl?zip=$1 [R]
> RewriteRule     ^(.*)         http://.../DEFAULT [R]
>
> The first of these rules intended to rewrite only if a 5 number zip exists.
> The second to redirect everything else.  Unfortunately, that much of a
> wildcard also seems to grap 5-digit zips as well.  I'm sure this is simply a
> regex thing, which I'm not that great at.  How would I get it to redirect
> everything except for the 5-digit zip?

The easy way would simply be to add the "L" flag to the first
RewriteRule (use [R,L]).  This should stop processing at that point
for matching requests.  Otherwise, you can add something like this
before the second RewriteRule:
RewriteCond %{REQUEST_URI} ^/[0-9]{5}$

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Troubles w/mod_rewrite

Posted by Jason Williard <jw...@pcsafe.com>.
You were right... As soon as I removed the leading slash, the problem was
solved.  But now I have another issue...

While I want this rewrite to occur, I also want everything else to redirect
to a default URL.  To do this, I added the following:

RewriteRule     ^([0-9]{5})   http://.../weather.pl?zip=$1 [R]
RewriteRule     ^(.*)         http://.../DEFAULT [R]

The first of these rules intended to rewrite only if a 5 number zip exists.
The second to redirect everything else.  Unfortunately, that much of a
wildcard also seems to grap 5-digit zips as well.  I'm sure this is simply a
regex thing, which I'm not that great at.  How would I get it to redirect
everything except for the 5-digit zip?
 
----
Thank You,
Jason Williard


On 1/19/06, Jason Williard <jw...@pcsafe.com> wrote:
> I added the RewriteLog directive to the .htaccess file and am now getting
> Internal Error messages.  When looking at the error logs, I get:
>
> [Thu Jan 19 13:20:08 2006] [alert] [client x.x.x.x]
> /www/vhosts/domain.com/weather/.htaccess: RewriteLog not allowed here

RewriteLog needs to be defined in httpd.conf.

But given that you are using .htaccess (which I didn't notice before),
you can probably solve your problem by removing the leading slash from
your RewriteRules.  This is not present when mod_rewrite is applied at
the <Directory>/.htaccess level.

(Of course, you would easily note this if you used the RewriteLog to
analyze the request.)

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Troubles w/mod_rewrite

Posted by Joshua Slive <jo...@slive.ca>.
On 1/19/06, Jason Williard <jw...@pcsafe.com> wrote:
> I added the RewriteLog directive to the .htaccess file and am now getting
> Internal Error messages.  When looking at the error logs, I get:
>
> [Thu Jan 19 13:20:08 2006] [alert] [client x.x.x.x]
> /www/vhosts/domain.com/weather/.htaccess: RewriteLog not allowed here

RewriteLog needs to be defined in httpd.conf.

But given that you are using .htaccess (which I didn't notice before),
you can probably solve your problem by removing the leading slash from
your RewriteRules.  This is not present when mod_rewrite is applied at
the <Directory>/.htaccess level.

(Of course, you would easily note this if you used the RewriteLog to
analyze the request.)

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Troubles w/mod_rewrite

Posted by Jason Williard <jw...@pcsafe.com>.
I added the RewriteLog directive to the .htaccess file and am now getting
Internal Error messages.  When looking at the error logs, I get:

[Thu Jan 19 13:20:08 2006] [alert] [client x.x.x.x]
/www/vhosts/domain.com/weather/.htaccess: RewriteLog not allowed here

The entry in the .htaccess file looks like:
RewriteLog     "logs/rewrite.log"


Any ideas why this may be happening?
 
----
Thank You,
Jason Williard



On 1/19/06, Jason Williard <jw...@pcsafe.com> wrote:
> I have a site that shows weather forecasts.  I would like create a
> RewriteRule to redirect to the proper URL when someone appends their
zipcode
> to the base url.
>
> i.e. http://weather.domain.com/12345 ->
> http://www.domain.com/cgi-bin/weather/weather.pl?zip=12345
>
> So far, I have tried several methods but cannot get it to work.  Here are
my
> current rules in the .htaccess file:
>
> RewriteEngine   On
> RewriteRule     ^/([^/]*)
> http://www.domain.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
>
> I have also tried each of the following:
>
> RewriteRule     ^/([^/][0-9])
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([^/][0-9]{5})
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([0-9]{5})
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([0-9])
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
>
> None of these have worked.  I simply get a 404 Not Found error.  However,
I
> know that mod_rewrite is working as I had another rule in place for
> redirecting anything that goes to that page to the default URL.
>
> Any ideas?

Use the RewriteLog to see what mod_rewrite is doing.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Troubles w/mod_rewrite

Posted by Joshua Slive <jo...@slive.ca>.
On 1/19/06, Jason Williard <jw...@pcsafe.com> wrote:
> I have a site that shows weather forecasts.  I would like create a
> RewriteRule to redirect to the proper URL when someone appends their zipcode
> to the base url.
>
> i.e. http://weather.domain.com/12345 ->
> http://www.domain.com/cgi-bin/weather/weather.pl?zip=12345
>
> So far, I have tried several methods but cannot get it to work.  Here are my
> current rules in the .htaccess file:
>
> RewriteEngine   On
> RewriteRule     ^/([^/]*)
> http://www.domain.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
>
> I have also tried each of the following:
>
> RewriteRule     ^/([^/][0-9])
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([^/][0-9]{5})
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([0-9]{5})
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
> RewriteRule     ^/([0-9])
> http://www.searching.com/cgi-bin/weather/weather.pl?zip=$1 [PT,QSA]
>
> None of these have worked.  I simply get a 404 Not Found error.  However, I
> know that mod_rewrite is working as I had another rule in place for
> redirecting anything that goes to that page to the default URL.
>
> Any ideas?

Use the RewriteLog to see what mod_rewrite is doing.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org