Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apache mod_rewrite question



So I fiddled around and came up with this:

RewriteRule ^oldpage.php newpage.php?otherid=0 [QSA,R]

Why does this work? The only thing I can figure is that the query string is simply added to the end (as is says in the docs) of the new page. But I'm not even referencing the query string in the first part. Do I not need to do that? Does QSA take whatever the query string is and append it automatically to the new page?

Thanks,

Mark

-------------------------------

On Mar 1, 2006, at 12:19 PM, Brian V. Hughes wrote:

Mark Wheeler wrote:
-------------------------------------------------
Options +FollowSymlinks
RewriteEngine on
# Set the RewriteBase to "/" for the root level to base everything on... I guess.
RewriteBase /
RewriteRule ^oldpage.php(.+) newpage.php$1&otherid=0 [R]
-------------------------------------------------
The $1 should have all the variable stuff in it from the php.
So I'm looking for it to essentially do this:
oldpage.php?id=1 redirects to newpage.php?id=1&otherid=0
Why is this not working? Any help would be appreciated.

Because the RewriteRule directive doesn't parse anything beyond the path portion of the requested URL. If you want to capture the query string, you have to use a RewriteCond statement to store the query string in a regex back-reference. You can then make use of the RewriteCond's back-references in a succeeding RewriteRule statement. There's actually a shortcut for doing this (check the QSA flag in the mod_rewrite docs), but you need to modify the query string in the rewritten URL, so you can't use that.


Give this a try:

RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^oldpage.php newpage.php?otherid=0&%1 [R]

-Brian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden
References: 
 >Apache mod_rewrite question (From: Mark Wheeler <email@hidden>)
 >Re: Apache mod_rewrite question (From: "Brian V. Hughes" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.