You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bob Smith <id...@gmail.com> on 2006/05/25 20:33:59 UTC

[users@httpd] Using mod_rewrite with redirect

Hi all.  I have been successfule in setting up mod_rewrite the way I needed
too, but now I'm trying to use 'redirect' and mod_rewrite in the same
directory.  There are two requests that I need to do special redirects on,
so I'm not handling them with the 'all-in-one' rewrite.  Maybe it's best I
show you...

------  .htaccess ------
redirect 301 /shoppingcart/customer/pages.php?pageid=62
http://www.kegworks.com/home.php?cat=663
redirect 301 /shoppingcart/customer/pages.php?pageid=63
http://www.kegworks.com/company.php?pageid=34

RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} /shoppingcart/customer/ [NC]
RewriteRule ^(.*)$ /$1 [QSA,R=301]
------  .htaccess ------

It does what I need it to do for all the other pages, but it just seems to
ignore the two redirect commands, and shows this in the log file...

129.44.255.58   -       -       [25/May/2006:14:13:32 -0400]    GET
/shoppingcart/customer/pages.php?pageid=663 HTTP/1.1  301     331
-       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111
Firefox/1.5

129.44.255.58   -       -       [25/May/2006:14:13:33 -0400]    GET
/pages.php?pageid=62 HTTP/1.1        302     5       -       Mozilla/5.0
(X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5

I have hit the brick wall.

Re: [users@httpd] Using mod_rewrite with redirect

Posted by Joshua Slive <jo...@slive.ca>.
On 5/25/06, Bob Smith <id...@gmail.com> wrote:
> Hi all.  I have been successfule in setting up mod_rewrite the way I needed
> too, but now I'm trying to use 'redirect' and mod_rewrite in the same
> directory.  There are two requests that I need to do special redirects on,
> so I'm not handling them with the 'all-in-one' rewrite.  Maybe it's best I
> show you...
>
> ------  .htaccess ------
> redirect 301 /shoppingcart/customer/pages.php?pageid=62
> http://www.kegworks.com/home.php?cat=663
> redirect 301 /shoppingcart/customer/pages.php?pageid=63
> http://www.kegworks.com/company.php?pageid=34
>
> RewriteEngine On
> #RewriteCond %{REQUEST_FILENAME} /shoppingcart/customer/ [NC]
> RewriteRule ^(.*)$ /$1 [QSA,R=301]
> ------  .htaccess ------
>
> It does what I need it to do for all the other pages, but it just seems to
> ignore the two redirect commands, and shows this in the log file...
>
> 129.44.255.58    -       -       [25/May/2006:14:13:32 -0400]    GET
> /shoppingcart/customer/pages.php?pageid=663 HTTP/1.1  301
>   331     -       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8)
> Gecko/20051111 Firefox/1.5
>
>  129.44.255.58   -       -       [25/May/2006:14:13:33 -0400]    GET
> /pages.php?pageid=62 HTTP/1.1        302     5       -       Mozilla/5.0
> (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
>
> I have hit the brick wall.

Don't mix Redirect and RewriteRule; the order-of-processing can
confuse things.  The capabilities of RewrietRule are a strict superset
of those of Redirect, so there is no reason to use Redirect.  Convert
your Redirects into RewriteRules with the flags [R,L] on the end.  In
addition, neither Redirect nor RewriteRule will match against the
query string.  You need to add a RewriteCond %{QUERY_STRING} to do
that.

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