Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    36
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    371
    Thanks
    0
    Thanked 20 Times in 20 Posts
    %{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]

  • Users who have thanked schleppel for this post:

    benjam1nrk (05-27-2009)

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    36
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you schleppel!

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

  • #4
    New Coder
    Join Date
    Feb 2008
    Posts
    55
    Thanks
    1
    Thanked 0 Times in 0 Posts
    @schleppel: I've been added reputation for you, ^_^ thanks alot mate


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •