You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by thomas Armstrong <ta...@gmail.com> on 2007/05/30 17:46:25 UTC

[users@httpd] Problems with an extra Rewrite Rule before a RewriteCond

 Hi.

I'm trying to create an additional Rewrite Rule appart from those
created by default by my application (in this case, Wordpress). The
extra line (within '.htaccess') is:
-------
RewriteRule ^faq index.php?page_id=119 [R,L]
-------

However, I want users see 'http://myblog.com/faq' and not
'http://myblog.com/index.php?page_id=379'. This line works with other
Apache configurations, but not with mine. Any suggestion?

.htaccess
---------------------------------
RewriteEngine On
RewriteBase /
DirectoryIndex index.php

# MY OWN REWRITE RULES
RewriteRule ^faq index.php?page_id=119 [R,L]

# Rewrite www.domain.com to domain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*) http://%1/$1 [R,L]

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
------------------------------------------

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Joshua Slive <jo...@slive.ca>.
On 5/30/07, thomas Armstrong <ta...@gmail.com> wrote:
> > How exactly isn't is working?
> Instead of 'http://myblog.com/faq' URL I see
> 'http://myblog.com/index.php?page_id=379'. The information is OK, but
> I think it's an ugly URL.

Start by replacing the [R] flag with [PT] and then see what you get.

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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by thomas Armstrong <ta...@gmail.com>.
> How exactly isn't is working?
Instead of 'http://myblog.com/faq' URL I see
'http://myblog.com/index.php?page_id=379'. The information is OK, but
I think it's an ugly URL.

> Do you see a loop?
Nope

> What does the error log tell you?
There's no error

> Are you able to edit the main server config file to enable rewrite logging?
Yep, but I've got the same problem.

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Joshua Slive <jo...@slive.ca>.
On 6/1/07, thomas Armstrong <ta...@gmail.com> wrote:
> Thank you everybody.
>
> However I'm still gettint the same odd effect. I tried:
> RewriteRule ^faq index.php?page_id=119 [R,L] ---> it doesn't mask the URL
> RewriteRule ^faq index.php?page_id=119 [R,TP] --> Internal server error
> RewriteRule ^faq index.php?page_id=119 --> it's caught by index.php, I suppose

As you've been told repeatedly, you can't use "R" if you don't want
the browser to see the new URL.

So the only one of those that makes any sense at all is the last one.
But what the heck does "It's caught by index.php" mean? Isn't that the
idea? What exactly happens?

>
> I also tried by editting it on 'httpd.conf':
> RewriteRule http://myblog.com/faq http://myblog.com/index.php?page_id=119 [R,L]

That's a garbage config. Where did you get that from. Something closer would be
RewriteRule ^/faq /index.php?page_id=119 [L]
and perhaps better
RewriteRule ^/faq /full/path/to/index.php?page_id=119 [L]

If you still can't get it to work, you MUST use the RewriteLog to
debug your problems. Using mod_rewrite with the RewriteLog is just
flailing in the dark.

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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by thomas Armstrong <ta...@gmail.com>.
Thank you everybody.

However I'm still gettint the same odd effect. I tried:
RewriteRule ^faq index.php?page_id=119 [R,L] ---> it doesn't mask the URL
RewriteRule ^faq index.php?page_id=119 [R,TP] --> Internal server error
RewriteRule ^faq index.php?page_id=119 --> it's caught by index.php, I suppose

I also tried by editting it on 'httpd.conf':
RewriteRule http://myblog.com/faq http://myblog.com/index.php?page_id=119 [R,L]
..

But I'm not sure Apache is taking it into account. :(

On 5/30/07, Vincent Bray <no...@gmail.com> wrote:
> On 30/05/07, Russ <rs...@istandfor.com> wrote:
> > I'm a bit confused.  R means redirect, meaning the server sends the 301 or 302 header to the browser.  In either case, the browse will redirect to the new URL and that's what will show in the address bar.  How evactly do you make things redirect without proxying and without a change in the address bar?
>
> Do as Joshua pointed out. First try without any flags at all, and in
> case that doesn't work try with [PT].
>
> I expect you won't need any flags.
>
> --
> noodl
>
> ---------------------------------------------------------------------
> 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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Vincent Bray <no...@gmail.com>.
On 30/05/07, Russ <rs...@istandfor.com> wrote:
> I'm a bit confused.  R means redirect, meaning the server sends the 301 or 302 header to the browser.  In either case, the browse will redirect to the new URL and that's what will show in the address bar.  How evactly do you make things redirect without proxying and without a change in the address bar?

Do as Joshua pointed out. First try without any flags at all, and in
case that doesn't work try with [PT].

I expect you won't need any flags.

-- 
noodl

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Russ <rs...@istandfor.com>.
I'm a bit confused.  R means redirect, meaning the server sends the 301 or 302 header to the browser.  In either case, the browse will redirect to the new URL and that's what will show in the address bar.  How evactly do you make things redirect without proxying and without a change in the address bar?  

Russ
Sent wirelessly via BlackBerry from T-Mobile.  

-----Original Message-----
From: "Vincent Bray" <no...@gmail.com>
Date: Wed, 30 May 2007 17:33:47 
To:users@httpd.apache.org, rsivak@istandfor.com
Subject: Re: [users@httpd] Problems with an extra Rewrite Rule before a RewriteCond

On 30/05/07, Russ <rs...@istandfor.com> wrote:
> The R flag means redirect.  You want P for proxy if you want the URL to not change, but this brings with it a host of other issues.

Russ, you're correct regarding [R] but incorrect pertaining to [P] in
this case. He's rewriting to a local script so there's no need for
proxying. And as he requested, the client won't see the change.

However, I suspect he'll see a loop as this is in .htaccess and
further down the ruleset '.' is rewritten to index.php again.

Thomas, if you get a loop, add this line before your custom rule:
RewriteCond %{REQUEST_URI} !index.php

-- 
noodl

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Vincent Bray <no...@gmail.com>.
On 30/05/07, Russ <rs...@istandfor.com> wrote:
> The R flag means redirect.  You want P for proxy if you want the URL to not change, but this brings with it a host of other issues.

Russ, you're correct regarding [R] but incorrect pertaining to [P] in
this case. He's rewriting to a local script so there's no need for
proxying. And as he requested, the client won't see the change.

However, I suspect he'll see a loop as this is in .htaccess and
further down the ruleset '.' is rewritten to index.php again.

Thomas, if you get a loop, add this line before your custom rule:
RewriteCond %{REQUEST_URI} !index.php

-- 
noodl

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Russ <rs...@istandfor.com>.
The R flag means redirect.  You want P for proxy if you want the URL to not change, but this brings with it a host of other issues.

Russ
Sent wirelessly via BlackBerry from T-Mobile.  

-----Original Message-----
From: "Vincent Bray" <no...@gmail.com>
Date: Wed, 30 May 2007 17:02:25 
To:users@httpd.apache.org
Subject: Re: [users@httpd] Problems with an extra Rewrite Rule before a RewriteCond

On 30/05/07, thomas Armstrong <ta...@gmail.com> wrote:
>  Hi.
>
> I'm trying to create an additional Rewrite Rule appart from those
> created by default by my application (in this case, Wordpress). The
> extra line (within '.htaccess') is:
> -------
> RewriteRule ^faq index.php?page_id=119 [R,L]
> -------
>
> However, I want users see 'http://myblog.com/faq' and not
> 'http://myblog.com/index.php?page_id=379'. This line works with other
> Apache configurations, but not with mine. Any suggestion?

How exactly isn't is working? Do you see a loop? What does the error
log tell you? Are you able to edit the main server config file to
enable rewrite logging?

-- 
noodl

---------------------------------------------------------------------
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] Problems with an extra Rewrite Rule before a RewriteCond

Posted by Vincent Bray <no...@gmail.com>.
On 30/05/07, thomas Armstrong <ta...@gmail.com> wrote:
>  Hi.
>
> I'm trying to create an additional Rewrite Rule appart from those
> created by default by my application (in this case, Wordpress). The
> extra line (within '.htaccess') is:
> -------
> RewriteRule ^faq index.php?page_id=119 [R,L]
> -------
>
> However, I want users see 'http://myblog.com/faq' and not
> 'http://myblog.com/index.php?page_id=379'. This line works with other
> Apache configurations, but not with mine. Any suggestion?

How exactly isn't is working? Do you see a loop? What does the error
log tell you? Are you able to edit the main server config file to
enable rewrite logging?

-- 
noodl

---------------------------------------------------------------------
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