Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2009, 06:48 PM   PM User | #1
benjam1nrk
New Coder

 
Join Date: Feb 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
benjam1nrk is an unknown quantity at this point
ModRewrite Question

Hello,
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:

Code:
#Shorten URLs entered in original link form
RewriteCond %{ENV:REDIRECT_STATUS} ^.
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:
Code:
#RewriteCond %{ENV:REDIRECT_STATUS} ^.
#RewriteCond %{QUERY_STRING} ^PaymentID=(.*)$
#RewriteRule ^payment.php$ /payment/%1? [R,L]
Thank you for any assistance!
benjam1nrk is offline   Reply With Quote
Old 05-27-2009, 12:27 AM   PM User | #2
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
%{ENV:REDIRECT_STATUS} should be empty when redirecting.

Try
Code:
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^pricing\.php$ /pricing [NC,R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
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]
schleppel is offline   Reply With Quote
Users who have thanked schleppel for this post:
benjam1nrk (05-27-2009)
Old 05-27-2009, 02:22 AM   PM User | #3
benjam1nrk
New Coder

 
Join Date: Feb 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
benjam1nrk is an unknown quantity at this point
Thank you schleppel!

Works perfect, just needed to change the separator from / to - as it was messing with my relative image paths etc.
benjam1nrk is offline   Reply With Quote
Old 06-11-2009, 07:47 AM   PM User | #4
destruction
New Coder

 
Join Date: Feb 2008
Posts: 55
Thanks: 1
Thanked 0 Times in 0 Posts
destruction is an unknown quantity at this point
@schleppel: I've been added reputation for you, ^_^ thanks alot mate
destruction is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25 AM.


Advertisement
Log in to turn off these ads.