View Full Version : ModRewrite Question

05-25-2009, 06:48 PM
I am using a htaccess mod rewrite rule which redirects http://mysite.com/payment/PaymentID to http://mysite.com/payment.php?ID=PaymentID. This redirect works perfectly.

I would also like to rewrite the rule so http://mysite.com/payment/PaymentID appears in the browser URL. I have done this with pages with no query string. For example accessing http://mysite.com/pricing redirects to http://mysite.com/pricing.php but http://mysite.com/pricing still appears in the browser URL. Below is an example of my htaccess:

#Shorten URLs entered in original link form
RewriteRule ^ - [L]
RewriteRule ^pricing.php$ /pricing [R=301,L]

#Point short URL's to correct file
RewriteRule ^pricing$ pricing.php [NC,L]

How would I go about rewriting the URL if it contains a query string? I have something like this so far, but does not work:
#RewriteCond %{ENV:REDIRECT_STATUS} ^.
#RewriteCond %{QUERY_STRING} ^PaymentID=(.*)$
#RewriteRule ^payment.php$ /payment/%1? [R,L]

Thank you for any assistance!

05-27-2009, 12:27 AM
%{ENV:REDIRECT_STATUS} should be empty when redirecting.


Options +FollowSymLinks

RewriteEngine On

RewriteRule ^pricing\.php$ /pricing [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?PaymentID=([^&]+)(&.*)?$ [NC]
RewriteRule ^payment\.php$ /payment/%2? [NC,R=301,L]

RewriteRule ^pricing$ /pricing.php [NC,QSA,L]
RewriteRule ^payment/([^/]+)/?$ payment.php?ID=$1 [QSA,L]

05-27-2009, 02:22 AM
Thank you schleppel!

Works perfect, just needed to change the separator from / to - as it was messing with my relative image paths etc.

06-11-2009, 07:47 AM
@schleppel: I've been added reputation for you, ^_^ thanks alot mate

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum