Return-Path: Delivered-To: apmail-httpd-users-archive@www.apache.org Received: (qmail 64612 invoked from network); 22 Apr 2008 13:21:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Apr 2008 13:21:22 -0000 Received: (qmail 13818 invoked by uid 500); 22 Apr 2008 13:21:09 -0000 Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 13794 invoked by uid 500); 22 Apr 2008 13:21:09 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 13763 invoked by uid 99); 22 Apr 2008 13:21:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2008 06:21:09 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [64.191.174.81] (HELO cabernet.rcbowen.com) (64.191.174.81) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2008 13:20:14 +0000 Received: from [172.20.44.84] (seraphim.asbury.edu [63.174.94.2]) by cabernet.rcbowen.com (Postfix) with ESMTP id 2569F132A147; Tue, 22 Apr 2008 09:20:34 -0400 (EDT) In-Reply-To: <480DB6A5.2080300@knmedical.se> References: <480DB6A5.2080300@knmedical.se> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/alternative; boundary=Apple-Mail-11-782481472 Message-Id: <5BC5C615-50B8-415F-BD56-321351E41B19@rcbowen.com> From: Rich Bowen Date: Tue, 22 Apr 2008 09:20:31 -0400 To: users@httpd.apache.org X-Mailer: Apple Mail (2.753) X-Virus-Checked: Checked by ClamAV on apache.org Subject: Re: [users@httpd] RewriteCond and Rule --Apple-Mail-11-782481472 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Apr 22, 2008, at 05:57, Emil Edeholt wrote: > Hello! > > I've been trying to make my urls look like site.com/foo instead of > site.com/index.php?page=foo so I have one rewriterurl that > rewrites /foo to my php script and one rule that redirects old > index.php-url:s to my new urls. When I apply both rules they end up > in an infinite loop that I just can't get to stop. I've tried > adding a lot of different conds, but I can't get it to work. > > # If the url does not contain index.php rewrite to index.php script > RewriteCond %{REQUEST_URI} !index\.php > RewriteRule ^([a-z_]*)$ index.php?page=$1 [L] > > > # If the url does contain index.php redirect to /foo > RewriteCond %{REQUEST_URI} index\.php > RewriteCond %{QUERY_STRING} page=([a-z_]*) > RewriteRule ^index.php$ /base/path/%1? [R=301,L] > > Any ideas? Well, it's doing what you told it to do - if it's for /foo it redirects it to index.php?page=foo and if it's index.php it redirects it to /foo While I understand what you're trying to accomplish - only letting people see the "/foo" version - this just isn't going to work, particularly not in a .htaccess file. Your best bet is to drop the second ruleset, and just ensure that all HTML links contain the desired URL rather than the actual one. It's possible (I haven't tested this, not certain) that if you are able to move this to the main configuration file, and add a [PT] to the first ruleset and a [NS] to the second ruleset, that it'll do what you mean. But I rather suspect not. -- "There are two kinds of light--the glow that illuminates, and the glare that obscures." James Thurber --Apple-Mail-11-782481472 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=US-ASCII
On Apr 22, 2008, at 05:57, Emil Edeholt wrote:

Hello!

I've been trying to make my urls = look like site.com/foo instead of site.com/index.php?page=3Dfoo so I = have one rewriterurl that rewrites /foo to my php script and one rule = that redirects old index.php-url:s to my new urls. When I apply both = rules they end up in an infinite loop that I just can't get to stop. = I've tried adding a lot of different conds, but I can't get it to = work.

# If the url does not contain index.php rewrite to = index.php script
RewriteCond %{REQUEST_URI} = !index\.php
RewriteRule ^([a-z_]*)$ = index.php?page=3D$1 [L]


# If the url does contain index.php redirect to = /foo
RewriteCond %{REQUEST_URI} = index\.php
RewriteCond %{QUERY_STRING} = page=3D([a-z_]*)
RewriteRule ^index.php$ = /base/path/%1? [R=3D301,L]

Any = ideas?

Well, it's doing what you told = it to do - if it's for /foo it redirects it to index.php?page=3Dfoo and = if it's index.php it redirects it to /foo
While I understand = what you're trying to accomplish - only letting people see the "/foo" = version - this just isn't going to work, particularly not in a .htaccess = file. Your best bet is to drop the second ruleset, and just ensure that = all HTML links contain the desired URL rather than the actual = one.

It's possible (I haven't tested this, not = certain) that if you are able to move this to the main configuration = file, and add a [PT] to the first ruleset and a [NS] to the second = ruleset, that it'll do what you mean. But I rather suspect = not.

--
"There are two kinds of light--the glow that = illuminates, and the glare that obscures."
James = Thurber

=

= --Apple-Mail-11-782481472--